|
From: Jérôme <je...@jo...> - 2011-12-07 19:46:50
|
Hi all.
The position of an axes is fixed at creation, regardless of the what goes
outside the plot area. If the numbers on the y-axis are big enough (say, 7
digits) and a label is added, the label gets out of the figure.
Example :
--------------------------------------------------------------------------
import pylab
data = [0,1,2,3000000]
fig = pylab.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.plot(data)
ax1.set_ylabel('label_axis_y1')
pylab.show()
--------------------------------------------------------------------------
Is there a way to automatically resize the axis and nicely center the whole
set {axes + ticklabels + labels} in the figure ?
One could use add_axes and play with the coordinates until he gets something
nice, but it gets complicated to have it automatic as things depends on
- the number of digits of y-axis ticklabels
- whether or not a secundary y-axis is added on the right (using twinx)
Or did I miss something ?
Thanks.
--
Jérôme
|
|
From: Jérôme <je...@jo...> - 2011-12-07 19:57:44
|
Hi again.
Wed, 7 Dec 2011 20:29:22 +0100
Jérôme a écrit:
> Is there a way to automatically resize the axis and nicely center the whole
> set {axes + ticklabels + labels} in the figure ?
[...]
> Or did I miss something ?
It seems I missed figure.tight_layout().
Sorry about that...
--
Jérôme
|
|
From: Jérôme <je...@jo...> - 2011-12-07 20:26:14
|
Wed, 7 Dec 2011 20:29:22 +0100
Jérôme a écrit:
> Is there a way to automatically resize the axis and nicely center the whole
> set {axes + ticklabels + labels} in the figure ?
>
> One could use add_axes and play with the coordinates until he gets something
> nice, but it gets complicated to have it automatic as things depends on
> - the number of digits of y-axis ticklabels
> - whether or not a secundary y-axis is added on the right (using twinx)
Hi again, sorry for multi-posting.
Apparently, figure.tight_layout() does not take into account the secondary
y-axis on the right.
Is this a known limitation ? (I don't see it on the caveats paragraph [1].)
Or is this the use I make of it that is incorrect ?
Example :
--------------------------------------------------------------------------
import pylab
fig = pylab.figure()
data_1 = [0,1,2,3]
data_2 = [0,5,250,30000]
lines = []
# Primary axis
ax1 = fig.add_subplot(1,1,1)
lines.extend (ax1.plot(data_1, 'b'))
# Secondary axis
ax2 = pylab.twinx(ax1)
lines.extend (ax2.plot(data_2, 'g'))
labels = ['Data 1', 'Data 2']
fig.tight_layout()
pylab.show()
--------------------------------------------------------------------------
Thanks.
[1] http://matplotlib.sourceforge.net/users/tight_layout_guide.html
--
Jérôme
|
|
From: Jae-Joon L. <lee...@gm...> - 2012-03-04 07:45:37
|
tight_layout only works for instances of Subplots. However, ax2, which is created by calling twinx, is an instance of Axes, and is not accounted by the tight_layout command.It may be possible to improve the situation, I doubt it would be easy as the association between ax1 and ax2 is not very explicit in the current implementation. One workaround is to use axes_grid1 toolkit (this works with current git master branch but not sure if it will work with v1.1). Try to replace ax1 = fig.add_subplot(1,1,1) with from mpl_toolkits.axes_grid1.parasite_axes import SubplotHost ax1 = SubplotHost(fig, 1, 1, 1) fig.add_subplot(ax1) -JJ On Thu, Dec 8, 2011 at 5:28 AM, Jérôme <je...@jo...> wrote: > Wed, 7 Dec 2011 20:29:22 +0100 > Jérôme a écrit: > >> Is there a way to automatically resize the axis and nicely center the whole >> set {axes + ticklabels + labels} in the figure ? >> >> One could use add_axes and play with the coordinates until he gets something >> nice, but it gets complicated to have it automatic as things depends on >> - the number of digits of y-axis ticklabels >> - whether or not a secundary y-axis is added on the right (using twinx) > > Hi again, sorry for multi-posting. > > Apparently, figure.tight_layout() does not take into account the secondary > y-axis on the right. > > Is this a known limitation ? (I don't see it on the caveats paragraph [1].) > > Or is this the use I make of it that is incorrect ? > > Example : > > -------------------------------------------------------------------------- > > import pylab > > fig = pylab.figure() > > data_1 = [0,1,2,3] > data_2 = [0,5,250,30000] > > lines = [] > > # Primary axis > ax1 = fig.add_subplot(1,1,1) > lines.extend (ax1.plot(data_1, 'b')) > > # Secondary axis > ax2 = pylab.twinx(ax1) > lines.extend (ax2.plot(data_2, 'g')) > > labels = ['Data 1', 'Data 2'] > > fig.tight_layout() > > pylab.show() > > > -------------------------------------------------------------------------- > > Thanks. > > [1] http://matplotlib.sourceforge.net/users/tight_layout_guide.html > > -- > Jérôme > > ------------------------------------------------------------------------------ > Cloud Services Checklist: Pricing and Packaging Optimization > This white paper is intended to serve as a reference, checklist and point of > discussion for anyone considering optimizing the pricing and packaging model > of a cloud services business. Read Now! > http://www.accelacomm.com/jaw/sfnl/114/51491232/ > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |