## matplotlib-users

 [Matplotlib-users] plotyy equivalent? From: Cory Davis - 2005-05-11 21:06:51 ```Hi All, I am wanting to make a plot with a secondary y axis, just like the matlab function plotyy does. Does anyone have any tips on how to do this with matplotlib? Cheers, Cory. -- --------------------------------------------------- Cory Davis Institute for Atmospheric and Environmental Science Room 307, Crew Building, Kings Buildings, University of Edinburgh. Edinburgh EH9 3JN phone: +44 131 6505092 www: http://www.geos.ed.ac.uk/contacts/homes/cdavis ```
 [Matplotlib-users] Re: plotyy equivalent? From: Cory Davis - 2005-05-11 23:04:41 ```Hi all, I have now figured out how to do this. It goes something like... x=arange(10) y1=sin(x) y2=10*cos(x) rect=[0.1,0.1,0.8,0.8] a1=axes(rect) a1.yaxis.tick_left() plot(x,y1) ylabel('axis 1') xlabel('x') a2=axes(rect,frameon=False) a2.yaxis.tick_right() plot(x,y2) a2.yaxis.set_label_position('right') ylabel('axis 2') a2.set_xticks([]) Cheers, Cory. Cory Davis wrote: > Hi All, > I am wanting to make a plot with a secondary y axis, just like the > matlab function plotyy does. Does anyone have any tips on how to do this > with matplotlib? > > Cheers, > Cory. > > ```
 Re: [Matplotlib-users] Re: plotyy equivalent? From: John Hunter - 2005-05-12 01:09:35 ```>>>>> "Cory" == Cory Davis writes: Cory> Hi all, I have now figured out how to do this. It goes Cory> something like... That's the basic idea -- matplotlib has some helper functions to make this easier -- see examples/shared_axis_demo.py What is the signature of plotyy -- I wasn't aware of this function.. JDH ```
 Re: [Matplotlib-users] Re: plotyy equivalent? From: Cory Davis - 2005-05-12 07:41:46 ```Hi John, here is the plotyy help info. Cory. >> help plotyy PLOTYY Graphs with y tick labels on the left and right. PLOTYY(X1,Y1,X2,Y2) plots Y1 versus X1 with y-axis labeling on the left and plots Y2 versus X2 with y-axis labeling on the right. PLOTYY(X1,Y1,X2,Y2,FUN) uses the plotting function FUN instead of PLOT to produce each plot. FUN should be a function handle to a plotting function, e.g. @plot, @semilogx, @semilogy, @loglog ,@stem, etc. that accepts the syntax H = FUN(X,Y). PLOTYY(X1,Y1,X2,Y2,FUN1,FUN2) uses FUN1(X1,Y1) to plot the data for the left axes and FUN2(X1,Y1) to plot the data for the right axes. [AX,H1,H2] = PLOTYY(...) returns the handles of the two axes created in AX and the handles of the graphics objects from each plot in H1 and H2. AX(1) is the left axes and AX(2) is the right axes. See also PLOT, @. >> John Hunter wrote: >>>>>>"Cory" == Cory Davis writes: > > > Cory> Hi all, I have now figured out how to do this. It goes > Cory> something like... > > That's the basic idea -- matplotlib has some helper functions to make > this easier -- see examples/shared_axis_demo.py > > What is the signature of plotyy -- I wasn't aware of this function.. > > JDH > > > ------------------------------------------------------- > This SF.Net email is sponsored by Oracle Space Sweepstakes > Want to be the first software developer in space? > Enter now for the Oracle Space Sweepstakes! > http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- --------------------------------------------------- Cory Davis Institute for Atmospheric and Environmental Science Room 307, Crew Building, Kings Buildings, University of Edinburgh. Edinburgh EH9 3JN phone: +44 131 6505092 www: http://www.geos.ed.ac.uk/contacts/homes/cdavis ```
 Re: [Matplotlib-users] Re: plotyy equivalent? From: Stephen Walton - 2005-05-13 19:11:11 ```John Hunter wrote: > What is the signature of plotyy -- I wasn't aware of this function.. PLOTYY(X1,Y1,X2,Y2) plots Y1 versus X1 with y-axis labeling on the left and plots Y2 versus X2 with y-axis labeling on the right. PLOTYY(X1,Y1,X2,Y2,FUN) uses the plotting function FUN instead of PLOT to produce each graph. FUN can be a function handle or a string that is the name of a plotting function, e.g. plot, semilogx, semilogy, loglog, stem, etc. or any function that accepts the syntax H = FUN(X,Y). For example PLOTYY(X1,Y1,X2,Y2,@loglog) % Function handle PLOTYY(X1,Y1,X2,Y2,'loglog') % String I just happened to have MATLAB going in anohter window. ```
 [Matplotlib-users] Legends don't work in the polar plot. From: Ted Drain - 2005-05-12 02:16:09 ```Has anyone tried to put a legend in a polar plot? I get an error whenever I try this. To reproduce the error, run the polar plot demo and then do something like: legend( ( "test" ) ) File "/group/monte/development/rhe3/tools.0504/lib/python2.4/site-packages/matplotlib/pylab.py", line 2173, in legend ret = gca().legend(*args, **kwargs) File "/group/monte/development/rhe3/tools.0504/lib/python2.4/site-packages/matplotlib/axes.py", line 1881, in legend handles = [h for h, label in zip(get_handles(), labels)] File "/group/monte/development/rhe3/tools.0504/lib/python2.4/site-packages/matplotlib/axes.py", line 1869, in get_handles handles.extend(self.patches) AttributeError: PolarAxes instance has no attribute 'patches' Should I file this as a bug? Thanks, Ted Ted Drain Jet Propulsion Laboratory ted.drain@... ```
 Re: [Matplotlib-users] Legends don't work in the polar plot. From: John Hunter - 2005-05-12 14:29:55 ```>>>>> "Ted" == Ted Drain writes: Ted> Has anyone tried to put a legend in a polar plot? I get an Ted> error whenever I try this. To reproduce the error, run the Ted> polar plot demo and then do something like: Ted> legend( ( "test" ) ) Ted> "/group/monte/development/rhe3/tools.0504/lib/python2.4/site-packages/matplotlib/axes.py", Ted> line 1869, in get_handles handles.extend(self.patches) Ted> AttributeError: PolarAxes instance has no attribute 'patches' Ted> Should I file this as a bug? Thanks, Ted Ted Drain Jet Maybe a feature request? The problem is deeper than simply adding the missing patches attr (which holds a list of patches stored by the axes). If you add that (as I just did), you can run legend w/ no traceback but no legend either. I think the problem is that the legend by default uses the axes coordinate system to place the rectangle in which the legend resides is being placed in axes coordinates, and the axes coordinate system for polar axes is not the same as for rectangular axes and this is fouling up the legend placement. There is a workaround using figlegend >>> lines = polar(range(10)) >>> figlegend(lines, ('my label',), 'upper right') I think it would be nice for polar axes legend to work automagically, so you might want to add this as a feature request on the sf site. I already fixed the patch/traceback crash, but now it just fails silently (no legend, no error). I think I'll add an PolarAxes legend NotImplementedError which raises an exceptions and suggests figlegend for the time being. I'm sure there are other surprises one will find when trying to use some of the Axes parent methods (eg table) in the PolarAxes. It would be nice if these were also indicated with NotImplementedError until they are. We can fill these in as we find them. JDH ```
 Re: [Matplotlib-users] Legends don't work in the polar plot. From: Ted Drain - 2005-05-12 15:33:59 ```Thanks for the tip - figlegend works just fine for my application. I'll file an enhancement for tracking purposes... Ted At 07:29 AM 5/12/2005, John Hunter wrote: > >>>>> "Ted" == Ted Drain writes: > > Ted> Has anyone tried to put a legend in a polar plot? I get an > Ted> error whenever I try this. To reproduce the error, run the > Ted> polar plot demo and then do something like: > > Ted> legend( ( "test" ) ) > Ted> > "/group/monte/development/rhe3/tools.0504/lib/python2.4/site-packages/matplotlib/axes.py", > Ted> line 1869, in get_handles handles.extend(self.patches) > Ted> AttributeError: PolarAxes instance has no attribute 'patches' > > > Ted> Should I file this as a bug? Thanks, Ted Ted Drain Jet > >Maybe a feature request? The problem is deeper than simply adding the >missing patches attr (which holds a list of patches stored by the >axes). If you add that (as I just did), you can run legend w/ no >traceback but no legend either. I think the problem is that the >legend by default uses the axes coordinate system to place the >rectangle in which the legend resides is being placed in axes >coordinates, and the axes coordinate system for polar axes is not the >same as for rectangular axes and this is fouling up the legend >placement. > >There is a workaround using figlegend > > >>> lines = polar(range(10)) > >>> figlegend(lines, ('my label',), 'upper right') > >I think it would be nice for polar axes legend to work automagically, >so you might want to add this as a feature request on the sf site. I >already fixed the patch/traceback crash, but now it just fails >silently (no legend, no error). I think I'll add an PolarAxes legend >NotImplementedError which raises an exceptions and suggests figlegend >for the time being. > >I'm sure there are other surprises one will find when trying to use >some of the Axes parent methods (eg table) in the PolarAxes. It >would be nice if these were also indicated with NotImplementedError >until they are. We can fill these in as we find them. > >JDH ```