|
From: Ryan M. <rm...@gm...> - 2010-08-26 13:36:49
|
On Thu, Aug 26, 2010 at 1:55 AM, Tinne De Laet
<tin...@me...> wrote:
> Hi Carlos,
>
> On Thu, Aug 26, 2010 at 04:49, Carlos Grohmann
> <car...@gm...> wrote:
>> Hello all,
>>
>> Is there a way to tell MPL that something I plotted (like a series of
>> Line2D, to create a grid) should not be considered for the legend?
>>
>> I'm plotting a lot of things, and because of these objects (without
>> label), I always got these msgs:
>>
>> /usr/lib/pymodules/python2.6/matplotlib/axes.py:4014: UserWarning: No
>> labeled objects found. Use label='...' kwarg on individual plots.
>> warnings.warn("No labeled objects found. "
>>
> I always use the following set of commands to get costumize my legend:
>
> **************************************
> legendEntries=[] # list of plots that are going to be in
> the legend
> legendText=[] # list of text messages for the legend
>
> thisPlot = plot(x,y,'b*') # a plot command
>
> legendEntries.append(thisPlot) # only do this for the plots you want
> to add to the legend
> legendText.append("legend text") # only this for the plots you want
> to add to the legend
>
> lgd = legend(legendEntries,legendText,numpoints=1,prop=props,loc='upper
> right') # example of how to draw the legend
>
> **************************************
You can also leave out the label, or in a loop like this,
conditionally assign a label of '_nolegend_', which suppresses adding
it to the legend. This example shows how the different options work:
import numpy as np
import matplotlib.pyplot as plt
x1,y1 = np.random.rand(2,10)
x2,y2 = np.random.rand(2,10)
x3,y3 = np.random.rand(2,10)
x4,y4 = np.random.rand(2,10)
plt.plot(x1, y1, label='first')
plt.plot(x2, y2) # No label, so not included
plt.plot(x3, y3, label='_nolegend_') # Actively suppress
plt.plot(x4, y4, label='fourth')
plt.legend() # Only shows lines 'first' and 'fourth'
Ryan
--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
|