buq333 buq333 - 1 year ago 194
Python Question

python matplotlib legend linestyle '---'

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

character description
'-' solid line style
'--' dashed line style
'-.' dash-dot line style
':' dotted line style

I can see '-' and '--' in the list, but on the right up side, my legend comes up like " -- red dotted line" (If I write linestyle = '--'). I want '--- red dotted line' on my legend box

Is there any way I can make the legend show three dashes?
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