From: Thomas R. <tho...@gm...> - 2009-04-28 05:08:54
|
Hi, This is probably a simple question, but what is the best way to control the vertical positioning of the x-axis label? I tried: import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as mpl fig = mpl.figure() ax = fig.add_subplot(111) ax.set_xlabel("Hello",position=(0.5,-0.2)) fig.savefig('test.png') But this doesn't work. Strangely, changing the first position element does shift the label left and right, but changing the second does not move the label vertically. I'm using matplotlib 0.98.5.2 Thanks for any advice! Thomas |
From: Jouni K. S. <jk...@ik...> - 2009-04-28 05:39:32
|
Thomas Robitaille <tho...@gm...> writes: > This is probably a simple question, but what is the best way to > control the vertical positioning of the x-axis label? Matplotlib tries to set the vertical position automatically based on how tall the tick labels are - see how e.g. the commands setp(getp(gca(), 'xticklabels'), fontsize=2) setp(getp(gca(), 'xticklabels'), fontsize=10) setp(getp(gca(), 'xticklabels'), fontsize=20) affect the position. If you're not happy with that, I think your best bet is to use figtext instead of xlabel, and perhaps file a bug in the matplotlib tracker, explaining how the current positioning is insufficient for your needs. -- Jouni K. Seppänen http://www.iki.fi/jks |
From: Thomas R. <tho...@gm...> - 2009-04-28 12:52:43
|
Hi Jouni, Thanks for your help! Following what you suggested, I've decided to use ax.text(0.5,-0.13,xlabel,transform =ax.transAxes,ha='center',va='center') Thanks, Thomas On 28 Apr 2009, at 01:39, Jouni K. Seppänen wrote: > Thomas Robitaille <tho...@gm...> writes: > >> This is probably a simple question, but what is the best way to >> control the vertical positioning of the x-axis label? > > Matplotlib tries to set the vertical position automatically based on > how > tall the tick labels are - see how e.g. the commands > > setp(getp(gca(), 'xticklabels'), fontsize=2) > setp(getp(gca(), 'xticklabels'), fontsize=10) > setp(getp(gca(), 'xticklabels'), fontsize=20) > > affect the position. If you're not happy with that, I think your best > bet is to use figtext instead of xlabel, and perhaps file a bug in the > matplotlib tracker, explaining how the current positioning is > insufficient for your needs. > > -- > Jouni K. Seppänen > http://www.iki.fi/jks > > > ------------------------------------------------------------------------------ > Register Now & Save for Velocity, the Web Performance & Operations > Conference from O'Reilly Media. Velocity features a full day of > expert-led, hands-on workshops and two days of sessions from industry > leaders in dedicated Performance & Operations tracks. Use code > vel09scf > and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Yong-Duk J. <ne...@po...> - 2009-04-29 02:41:58
|
You can use 'LABELPAD' to adjust label position. e.g. import pylab hAxes = pylab.axes() pylab.xlabel('test') hAxes.xaxis.LABELPAD = 0 pylab.show() -- Yong-Duk Jin On Tuesday 28 April 2009 14:08:50 Thomas Robitaille wrote: > Hi, > > This is probably a simple question, but what is the best way to > control the vertical positioning of the x-axis label? I tried: > > import matplotlib > matplotlib.use('Agg') > import matplotlib.pyplot as mpl > > fig = mpl.figure() > ax = fig.add_subplot(111) > ax.set_xlabel("Hello",position=(0.5,-0.2)) > fig.savefig('test.png') > > But this doesn't work. Strangely, changing the first position element > does shift the label left and right, but changing the second does not > move the label vertically. > > I'm using matplotlib 0.98.5.2 > > Thanks for any advice! > > Thomas > > > --------------------------------------------------------------------------- >--- Register Now & Save for Velocity, the Web Performance & Operations > Conference from O'Reilly Media. Velocity features a full day of > expert-led, hands-on workshops and two days of sessions from industry > leaders in dedicated Performance & Operations tracks. Use code vel09scf > and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Thomas R. <tho...@gm...> - 2009-04-29 02:54:57
|
Thanks! I could not find any documentation relating to this, so I was wondering whether it would be better to go with a well-documented function such as text or figtext? What would be best to use? Thomas On 28 Apr 2009, at 22:27, Yong-Duk Jin wrote: > You can use 'LABELPAD' to adjust label position. > e.g. > > import pylab > hAxes = pylab.axes() > pylab.xlabel('test') > hAxes.xaxis.LABELPAD = 0 > pylab.show() > > -- > Yong-Duk Jin > > On Tuesday 28 April 2009 14:08:50 Thomas Robitaille wrote: >> Hi, >> >> This is probably a simple question, but what is the best way to >> control the vertical positioning of the x-axis label? I tried: >> >> import matplotlib >> matplotlib.use('Agg') >> import matplotlib.pyplot as mpl >> >> fig = mpl.figure() >> ax = fig.add_subplot(111) >> ax.set_xlabel("Hello",position=(0.5,-0.2)) >> fig.savefig('test.png') >> >> But this doesn't work. Strangely, changing the first position element >> does shift the label left and right, but changing the second does not >> move the label vertically. >> >> I'm using matplotlib 0.98.5.2 >> >> Thanks for any advice! >> >> Thomas >> >> >> --------------------------------------------------------------------------- >> --- Register Now & Save for Velocity, the Web Performance & >> Operations >> Conference from O'Reilly Media. Velocity features a full day of >> expert-led, hands-on workshops and two days of sessions from industry >> leaders in dedicated Performance & Operations tracks. Use code >> vel09scf >> and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf >> _______________________________________________ >> Matplotlib-users mailing list >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > > > > > ------------------------------------------------------------------------------ > Register Now & Save for Velocity, the Web Performance & Operations > Conference from O'Reilly Media. Velocity features a full day of > expert-led, hands-on workshops and two days of sessions from industry > leaders in dedicated Performance & Operations tracks. Use code > vel09scf > and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Ryan M. <rm...@gm...> - 2009-05-07 19:38:10
|
On Tue, Apr 28, 2009 at 9:54 PM, Thomas Robitaille < tho...@gm...> wrote: > Thanks! I could not find any documentation relating to this, so I was > wondering whether it would be better to go with a well-documented > function such as text or figtext? What would be best to use? > > Thomas > > On 28 Apr 2009, at 22:27, Yong-Duk Jin wrote: > > > You can use 'LABELPAD' to adjust label position. > > e.g. > > > > import pylab > > hAxes = pylab.axes() > > pylab.xlabel('test') > > hAxes.xaxis.LABELPAD = 0 > > pylab.show() > > > There's now a documented way to do this in SVN HEAD, by passing labelpad as an argument to the xlabel/ylabel functions. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma Sent from Norman, Oklahoma, United States |
From: Eric F. <ef...@ha...> - 2009-05-07 20:13:42
|
Ryan May wrote: > On Tue, Apr 28, 2009 at 9:54 PM, Thomas Robitaille > <tho...@gm... <mailto:tho...@gm...>> wrote: > > Thanks! I could not find any documentation relating to this, so I was > wondering whether it would be better to go with a well-documented > function such as text or figtext? What would be best to use? > > Thomas > > On 28 Apr 2009, at 22:27, Yong-Duk Jin wrote: > > > You can use 'LABELPAD' to adjust label position. > > e.g. > > > > import pylab > > hAxes = pylab.axes() > > pylab.xlabel('test') > > hAxes.xaxis.LABELPAD = 0 > > pylab.show() > > > > > There's now a documented way to do this in SVN HEAD, by passing labelpad > as an argument to the xlabel/ylabel functions. Ryan, Good idea, thanks. Quick thought, with no investigation on my part: wouldn't it be more natural and more useful if text placement pads like this were in font-size units, like the "em" and "ex", so that they would scale with the font size? I think that this would make the need to set them manually much less common. Eric > > Ryan > > -- > Ryan May > Graduate Research Assistant > School of Meteorology > University of Oklahoma > Sent from Norman, Oklahoma, United States > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your > production scanning environment may not be a perfect world - but thanks to > Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 > Series Scanner you'll get full speed at 300 dpi even with all image > processing features enabled. http://p.sf.net/sfu/kodak-com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Ryan M. <rm...@gm...> - 2009-05-07 20:17:13
|
On Thu, May 7, 2009 at 3:13 PM, Eric Firing <ef...@ha...> wrote: > Ryan May wrote: > >> On Tue, Apr 28, 2009 at 9:54 PM, Thomas Robitaille < >> tho...@gm... <mailto:tho...@gm...>> wrote: >> >> Thanks! I could not find any documentation relating to this, so I was >> wondering whether it would be better to go with a well-documented >> function such as text or figtext? What would be best to use? >> >> Thomas >> >> On 28 Apr 2009, at 22:27, Yong-Duk Jin wrote: >> >> > You can use 'LABELPAD' to adjust label position. >> > e.g. >> > >> > import pylab >> > hAxes = pylab.axes() >> > pylab.xlabel('test') >> > hAxes.xaxis.LABELPAD = 0 >> > pylab.show() >> > >> >> >> There's now a documented way to do this in SVN HEAD, by passing labelpad >> as an argument to the xlabel/ylabel functions. >> > > Ryan, > > Good idea, thanks. > > Quick thought, with no investigation on my part: wouldn't it be more > natural and more useful if text placement pads like this were in font-size > units, like the "em" and "ex", so that they would scale with the font size? > I think that this would make the need to set them manually much less > common. > > Good idea, I agree that might help. I was just going for somewhat of a quick hack, by just cleaning up access to a pre-existing constant. Right now it adds this pad value scaled by dpi/72.0 to an appropriate start in pixels. Any idea how the math could include a font size? Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma Sent from Norman, Oklahoma, United States |
From: Eric F. <ef...@ha...> - 2009-05-07 21:57:39
|
Ryan May wrote: > On Thu, May 7, 2009 at 3:13 PM, Eric Firing <ef...@ha... > <mailto:ef...@ha...>> wrote: > > Ryan May wrote: > > On Tue, Apr 28, 2009 at 9:54 PM, Thomas Robitaille > <tho...@gm... > <mailto:tho...@gm...> > <mailto:tho...@gm... > <mailto:tho...@gm...>>> wrote: > > Thanks! I could not find any documentation relating to this, > so I was > wondering whether it would be better to go with a well-documented > function such as text or figtext? What would be best to use? > > Thomas > > On 28 Apr 2009, at 22:27, Yong-Duk Jin wrote: > > > You can use 'LABELPAD' to adjust label position. > > e.g. > > > > import pylab > > hAxes = pylab.axes() > > pylab.xlabel('test') > > hAxes.xaxis.LABELPAD = 0 > > pylab.show() > > > > > There's now a documented way to do this in SVN HEAD, by passing > labelpad as an argument to the xlabel/ylabel functions. > > > Ryan, > > Good idea, thanks. > > Quick thought, with no investigation on my part: wouldn't it be more > natural and more useful if text placement pads like this were in > font-size units, like the "em" and "ex", so that they would scale > with the font size? I think that this would make the need to set > them manually much less common. > > > Good idea, I agree that might help. I was just going for somewhat of a > quick hack, by just cleaning up access to a pre-existing constant. > Right now it adds this pad value scaled by dpi/72.0 to an appropriate > start in pixels. Any idea how the math could include a font size? In any case where the text object exists at the time the calculation is needed, and the method doing the calculation has access to that object, it is just a matter of changing, for example, self.label.set_position( (x, bottom - self.labelpad*self.figure.dpi / 72.0)) to pad = (self.labelpad_rel * self.label.get_size() * self.figure.dpi / 72.0) self.label.set_position( (x, bottom - pad)) I think that most of the pads used in mpl are associated with text objects in such a way that this can be done. The question then becomes one of how to implement it in a way that doesn't wreck existing code, and doesn't create intolerable clutter. If this can be done, I think it would make a *significant* improvement in mpl usability--at least for anyone who needs to rescale plots for publication or for presentation display, for example. Another thing to watch out for in trying to make such a change: the pad calculation would need to be done late enough to reflect the font size at draw-time. I have not looked to see whether this is already the case, or whether it would require substantial refactoring. I was not suggesting that your labelpad patch should be changed right away, but rather using it as an opportunity to raise the larger design question, and see whether anyone is interested in pursuing it. I have raised questions about pad units before, and in fact we now have legend.borderpad (in legend font units) that replaces legend.pad (in normalized axes units). Eric > > Ryan > > -- > Ryan May > Graduate Research Assistant > School of Meteorology > University of Oklahoma > Sent from Norman, Oklahoma, United States |