Re: [Matplotlib-users] Dynamic adjustment of axis position and size in figure
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 jer...@jolimont.fr 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,3] 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Virtualization Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Dynamic adjustment of axis position and size in figure
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,300] 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 -- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Dynamic adjustment of axis position and size in figure
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 -- 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Dynamic adjustment of axis position and size in figure
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,3] 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 Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users