On Wed, Oct 27, 2010 at 5:31 PM, Alan G Isaac <[email protected]> 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
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users