Pyplot Legend only displaying one letter

时间:2017-06-19 13:56:27

标签: matplotlib

In a plot of wind resistance versus coefficients of drag, I have the following line defining the legend for the black dashed curve:

ax.legend(perpendicular_plate,'Flat Perpendicular Plate')

However, the legend is displaying only one letter of the name. I have used a legend many times, but never the ax.legend api...(top right corner)

enter image description here

What am I doing incorrectly to get this result?

1 个答案:

答案 0 :(得分:2)

You need to give the label(s) as an iterable of strings (i.e. a list or a tuple), even if there's only one label.

So, this should work:

ax.legend([perpendicular_plate],['Flat Perpendicular Plate'])

So what's happening in your case is because strings are iterable in python, its iterating on your string, and taking just the first item of the string (F), and using that.