1

I put 4 kinds of text in my plot.For example:

plt_text = plt.text(_x,_y,"o",color='r',fontsize = 15,label = "Buy")
plt_text = plt.text(_x,_y,"x",color='g',fontsize = 15,lable = "Sell")

But plt.legend() can't show the label of texts.How can I solve it?Thx.

I want to add labels for texts,not the figs that plt.plot maked.

Peng He
  • 2,023
  • 5
  • 17
  • 24
  • @PeCosta the (only) answer there definitely doesn't apply here. – DilithiumMatrix Dec 07 '15 at 03:02
  • Thank you.But ax.text return a Text,example:Text(3523,16.4,'o'),I can't use ax.legend(plt_text,["Buy"]).It seems ax.legend can just work on plot/bar/or else. – Peng He Dec 07 '15 at 03:07
  • @DilithiumMatrix Have you tried to add a text artist to a legend? Matplotlib prints a warning which says: "UserWarning: Legend does not support instances. A proxy artist may be used instead." So clearly PeCosta's comment applies here. – hitzg Dec 07 '15 at 08:49
  • @PengHe Could you explain why you want to do that? Are you trying to replicate what [plt.scatter](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter) is doing? – hitzg Dec 07 '15 at 08:51
  • @hitzg, oh "clearly"? Well... in that case... The OP wants to show the text itself as the legend-item, not as the description. So adding a proxy artist of a different object will *not* solve the problem. It is a relevant link, and its good that it was shared here, but it is ***clearly*** not a duplicate. – DilithiumMatrix Dec 07 '15 at 14:45
  • I drew a line and want to plot some different color points on some position which one kind of color have one meaning. The points is close to the line but not on the line. Finally, I used such as plt.plot(marker = 'o',color = 'k') to instead plt.text, and add legends for plt.plot. But I really want to know how I can add legend for texts.Do you have any ideas? – Peng He Dec 10 '15 at 05:39

0 Answers0