buq333 buq333 - 1 year ago 210
Python Question

python matplotlib linestyle '---'

I need a way to make matplotlib linestlye '---'. 3's of '-'.

character description
'-' solid line style
'--' dashed line style
'-.' dash-dot line style
':' dotted line style
'.' point marker
',' pixel marker
'o' circle marker
'v' triangle_down marker
'^' triangle_up marker
'<' triangle_left marker
'>' triangle_right marker
'1' tri_down marker
'2' tri_up marker
'3' tri_left marker
'4' tri_right marker
's' square marker
'p' pentagon marker
'*' star marker
'h' hexagon1 marker
'H' hexagon2 marker
'+' plus marker
'x' x marker
'D' diamond marker
'd' thin_diamond marker
'|' vline marker
'_' hline marker

I can see '-' and '--' in the list, but it's needed to be '---'.
Is there any way I can make dash to three?
Here's what I'm doing.

import matplotlib.pyplot as mpt

def main():
mpt.xlabel("x axis")
mpt.ylabel("y axis")
mpt.plot([1,2,3,4],[2,3,4,5],'r', linestyle = '???????')
mpt.legend(["red dotted line"])


Answer Source

Use mpt.legend(handlelength=3) and linestyle='--'

mpt.plot([1,2,3,4],[2,3,4,5],'r', linestyle='--')
mpt.legend(["red dotted line"], handlelength=3)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download