python - Why am I getting extra label text instead of the actual label that I put in? -
assume
import matplotlib.pyplot plt line_up, = plt.plot([1,2,3], label='line 2') line_down, = plt.plot([3,2,1], label='line 1') plt.legend([line_up, line_down], ['line up', 'line down']) i line 2d(line 1) if pass plt.legend() instead of label e.g. line 1. why so?
it script year old , can't remember came year ago!?
from script:
relevant_line, = plt.plot(x, relevant_normal_combination, label="relevant phrases distr.") # ... plt.legend([relevant_line, nonrelevant_line,relevant_mu, nonrelevant_mu], loc = 1) gives me:
the difference between example of doc , code, number of lists passed legend (two in doc, 1 in code)
let's take example bellow:
line_no_legend = plt.plot([1,2],[1,1],c="k") line_up, = plt.plot([1,2,3], label='line 2',color="b") line_down, = plt.plot([3,2,1], label='line 1',color="g") plt.legend([line_up, line_down], ['line up', 'line down']) #left plt.legend([line_up, line_down]) #middle plt.legend(handles=[line_up, line_down]) #right the left documentation, 2 list: handles , new labels (strings)
the middle 1 called 1 list, , has wrong colors , labels. that's because expects list of strings, not list of handles (see legend doc)
the right 1 fixes issue, specifying handles=.


Comments
Post a Comment