[Matplotlib-users] unwanted label clipping in gallery From: Alan G Isaac - 2010-10-27 22:31:45 Here is another example of unwanted text clipping in the gallery: http://matplotlib.sourceforge.net/examples/api/two_scales.html#api-two-scales (Both y axis labels are clipped.) I also think the example would be more complete if it 1. set a 270 degree rotation on the second ylabel, and 2. showed how to make a single legend for the two lines Btw, how *does* one best do 2? Cheers, Alan Isaac 
 Re: [Matplotlib-users] unwanted label clipping in gallery From: Paul Ivanov - 2010-10-28 00:21:37 Alan G Isaac, on 2010-10-27 18:31, wrote: > Here is another example of unwanted text clipping > in the gallery: > http://matplotlib.sourceforge.net/examples/api/two_scales.html#api-two-scales > (Both y axis labels are clipped.) > > I also think the example would be more complete if it > 1. set a 270 degree rotation on the second ylabel, and > 2. showed how to make a single legend for the two lines > > Btw, how *does* one best do 2? I don't know if it's best, but legend can take a list of objects and labels, so you can just grab all of the objects from the twin, and put them all in one legend: def onelegend_twinaxes(axis,twin): #make a joint axis legend lines = twin.get_lines() lines.extend(axis.get_lines()) labels = [l.get_label() for l in lines] return axis.legend(lines, labels) Here's a picture of what that looks like (thought I did some other prettifications). ; I wrote this in a solution set for a class I'm TAing this semester, so you can look at the whole thing here, if you'd like. the file is part of the solutions for Lab #1, it's called lab1.py (but actually links to lab1.txt): ; -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 
 Re: [Matplotlib-users] unwanted label clipping in gallery From: Alan G Isaac - 2010-10-29 01:29:22 On 10/27/2010 8:21 PM, Paul Ivanov wrote: > def onelegend_twinaxes(axis,twin): > #make a joint axis legend > lines = twin.get_lines() > lines.extend(axis.get_lines()) > labels = [l.get_label() for l in lines] > return axis.legend(lines, labels) That works. > ; Cool. What proportion of the students choose Python? Cheers, Alan 
 Re: [Matplotlib-users] unwanted label clipping in gallery From: Paul Ivanov - 2010-10-30 01:57:42 Alan G Isaac, on 2010-10-28 21:29, wrote: > On 10/27/2010 8:21 PM, Paul Ivanov wrote: > > def onelegend_twinaxes(axis,twin): > > #make a joint axis legend > > lines = twin.get_lines() > > lines.extend(axis.get_lines()) > > labels = [l.get_label() for l in lines] > > return axis.legend(lines, labels) > > That works. > > > ; > > Cool. What proportion of the students choose Python? This is the first time that Python's been officially encouraged, and it's been about 1 in 6. -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 
 Re: [Matplotlib-users] unwanted label clipping in gallery From: Ryan May - 2010-10-28 01:57:15 On Wed, Oct 27, 2010 at 5:31 PM, Alan G Isaac wrote: > Here is another example of unwanted text clipping > in the gallery: > http://matplotlib.sourceforge.net/examples/api/two_scales.html#api-two-scales > (Both y axis labels are clipped.) > > I also think the example would be more complete if it > 1. set a 270 degree rotation on the second ylabel, and > 2. showed how to make a single legend for the two lines > > Btw, how *does* one best do 2? For this example, saving the line objects will do. Then you just call legend with the objects. The new example looks thusly: import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(111) t = np.arange(0.01, 10.0, 0.01) s1 = np.exp(t) line1 = ax1.plot(t, s1, 'b-') ax1.set_xlabel('time (s)') # Make the y-axis label and tick labels match the line color. ax1.set_ylabel('exp', color='b') for tl in ax1.get_yticklabels(): tl.set_color('b') ax2 = ax1.twinx() s2 = np.sin(2*np.pi*t) line2 = ax2.plot(t, s2, 'r.') # Rotate ylabel 180 from normal y-axis label orientation ax2.set_ylabel('sin', color='r', rotation=270.) for tl in ax2.get_yticklabels(): tl.set_color('r') ax2.legend((line1, line2), ('exp(t)', '$sin(2 \pi t)$')) plt.show() Thanks for the suggestions. Any idea how the clipped figure problem was solved in the past? Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma 
 Re: [Matplotlib-users] unwanted label clipping in gallery From: Alan G Isaac - 2010-10-28 22:10:20 On 10/27/2010 9:56 PM, Ryan May wrote: > Any idea how the clipped figure problem > was solved in the past? http://www.mail-archive.com/matplotlib-users@.../msg18632.html http://www.mail-archive.com/matplotlib-users@.../msg18537.html fwiw, Alan 
 Re: [Matplotlib-users] unwanted label clipping in gallery From: Alan G Isaac - 2010-10-29 02:06:32 On 10/27/2010 9:56 PM, Ryan May wrote: > # Make the y-axis label and tick labels match the line color. > ax1.set_ylabel('exp', color='b') > for tl in ax1.get_yticklabels(): > tl.set_color('b') > Thanks. This is cool, but I think I find the colored tick labels visually distracting. Isn't a colored axis label enough? Cheers, Alan