You didn't label any of the series that you put on the graph, so the legend
has no idea what to call anything thing.

Like the warning (not error) says, use the label parameter on your calls to
plot, e.g., ax1.plot(..., label='Concentration') or whatever.

Note though, that you're mixing up interfaces in your script as written.
MPL's many interfaces are kind of mess, but you seem reasonably familiar
with the OO interface, so stick to that. What I mean is once you start
messing with ax1, and ax2 directly, don't revert back to call to plt. As
written, you'll only get a legend on ax2, but you haven't plotted anything
there.

If you want a legend on ax1, use ax1.legend.
-p

On Tue, Dec 2, 2014 at 1:59 AM, Tommy Carstensen <tommy.carsten...@gmail.com
> wrote:

> In gnuplot it is quite easy to create two axes, but I can't figure out
> how to do it in matplotlib. I'm trying this:
>
> import matplotlib
> matplotlib.use('Agg')
> import matplotlib.pyplot as plt
>
> for key1 in keys1:
>     ax1.plot(x, y, style, label=label, color=color, linewidth=3)
>     ax1.set_xlabel(xlabel)
>     ax1.set_ylabel(ylabel1)
>     ax2.set_ylabel(ylabel2)
>     plt.legend(loc='lower right', shadow=True)
>     plt.suptitle(title, fontsize=14, fontweight='bold')
>     axes = plt.gca()
>     axes.set_ylim([0,1])
>     plt.grid(b=True, which='major', color='k', linestyle='--')
>     plt.savefig('{}.png'.format(key1), dpi=600)
>     plt.close()
>     plt.clf()
>
> But I get this error:
> lib/python3.3/site-packages/matplotlib/axes.py:4749: UserWarning: No
> labeled objects found. Use label='...' kwarg on individual plots.
>   warnings.warn("No labeled objects found. "
>
> What am I doing wrong? Thanks.
>
>
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
>
> http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to