SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Sture L. <st...@ro...> - 2007年02月27日 09:02:14
Hi,
Quick question - how can I align ylabels for several subplots?
Sture
-- 
Sture Lygren
Computer Systems Administrator
Andoya Rocket Range
Work: +4776144451 / Fax: +4776144401
From: <jk...@ik...> - 2007年02月27日 09:39:50
Sture Lygren <st...@ro...> writes:
> Quick question - how can I align ylabels for several subplots?
Set their position properties e.g. like this:
 y = ylabel('foo')
 pos = getp(y, 'position')
 setp(y, 'position', (pos[0], X))
where X is the position (in data coordinates) where you want the
label. Depending on what kind of alignment you want, you may want to
set the verticalalignment property -- to see the properties and the
kind of values they can take, type setp(y), and to see their current
values, type getp(y).
If your subplots have different scales, you will want to set the
transform property, which is a little bit more complicated; there 
are examples at
 http://www.scipy.org/Cookbook/Matplotlib/Transformations 
-- 
Jouni K. Seppänen
http://www.iki.fi/jks
From: Sture L. <st...@ro...> - 2007年02月27日 17:42:53
Hi,
Thanks a lot for your reply. I still have some problem tough. I want
vertical alignment of 5 ylabels for 5 different subplots. Trying your
solution I'm able to move the ylabels up/down but not right/left. Seems
like changing 'x' in position (x,y) has no effect at all. How come?
regards,
Sture
Jouni K. Seppänen wrote:
> Sture Lygren <st...@ro...> writes:
> 
>> Quick question - how can I align ylabels for several subplots?
> 
> Set their position properties e.g. like this:
> 
> y = ylabel('foo')
> pos = getp(y, 'position')
> setp(y, 'position', (pos[0], X))
> 
> where X is the position (in data coordinates) where you want the
> label. Depending on what kind of alignment you want, you may want to
> set the verticalalignment property -- to see the properties and the
> kind of values they can take, type setp(y), and to see their current
> values, type getp(y).
> 
> If your subplots have different scales, you will want to set the
> transform property, which is a little bit more complicated; there 
> are examples at
> 
> http://www.scipy.org/Cookbook/Matplotlib/Transformations 
> 
-- 
Sture Lygren
Computer Systems Administrator
Andoya Rocket Range
Work: +4776144451 / Fax: +4776144401
From: Sture L. <st...@ro...> - 2007年02月27日 18:16:36
Should be horizontal alignment ...
Sture Lygren wrote:
> Hi,
> 
> Thanks a lot for your reply. I still have some problem tough. I want
> vertical alignment of 5 ylabels for 5 different subplots. Trying your
> solution I'm able to move the ylabels up/down but not right/left. Seems
> like changing 'x' in position (x,y) has no effect at all. How come?
> 
> regards,
> Sture
> 
> Jouni K. Seppänen wrote:
>> Sture Lygren <st...@ro...> writes:
>>
>>> Quick question - how can I align ylabels for several subplots?
>> Set their position properties e.g. like this:
>>
>> y = ylabel('foo')
>> pos = getp(y, 'position')
>> setp(y, 'position', (pos[0], X))
>>
>> where X is the position (in data coordinates) where you want the
>> label. Depending on what kind of alignment you want, you may want to
>> set the verticalalignment property -- to see the properties and the
>> kind of values they can take, type setp(y), and to see their current
>> values, type getp(y).
>>
>> If your subplots have different scales, you will want to set the
>> transform property, which is a little bit more complicated; there 
>> are examples at
>>
>> http://www.scipy.org/Cookbook/Matplotlib/Transformations 
>>
> 
-- 
Sture Lygren
Computer Systems Administrator
Andoya Rocket Range
Work: +4776144451 / Fax: +4776144401
From: John H. <jd...@gm...> - 2007年02月27日 18:38:54
On 2/27/07, Sture Lygren <st...@ro...> wrote:
> Thanks a lot for your reply. I still have some problem tough. I want
> vertical alignment of 5 ylabels for 5 different subplots. Trying your
> solution I'm able to move the ylabels up/down but not right/left. Seems
> like changing 'x' in position (x,y) has no effect at all. How come?
The ylabel position is layed out to not overlay the y tick labels --
if these are in different positions on each axes you will get the
ylabel in different positions. Two solutions:
 1) insure all the yticklabels have the same width by using a custom
formatter that fixes the tick widths.
 from matplotlib.ticker import FormatStrFormatter
 ax.yaxis.set_major_formatter(FormatStrFormatter('%1.3f'))
 2) do not use ylabels, but create your own using custom text
instances for labels
 ax.text(-0.1, 0.5, 'my label', transform=ax.transAxes, rotation=90,
ha='right', va='center')
The 2nd one is probably what you want.
JDH
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /