set limits not obeyed for stacked plots when set_aspect('equal') used

Hi all,

I've run across a minor but annoying bug. It can be demonstrated pretty
simply:

fig, ax = plt.subplots(2,1,sharex=True,figsize=(7.,7.))
fig.subplots_adjust(hspace=0.0)
x = 4.25*(np.arange(6.) - 2.5)/10.
y = 0.6*x/max(x)
ax[0].plot(x,y)
ax[0].set_xlim(-1.2,1.2)
ax[0].set_aspect('equal')
ax[1].plot(x,y)
ax[0].set_ylim(-0.6,0.6)
ax[1].set_ylim(-0.6,0.6)
ax[1].set_aspect('equal')
plt.show()

The problem is that the y limits on the two plots are slightly different
from those set:
ax[1].get_ylim()
(-0.61935483870967734, 0.61935483870967734)
and doing a set_ylim doesn't have any effect. This seems to be caused
by the set_aspect('equal'), since removing it results in plots with the
correct limits -- but aspect that is not quite equal. It is affected by
the figsize parameter in the call to subplots. It seems I can get the
correct y limits and aspect if I keep the set_aspect('equal') and fiddle
with the figsize. But that certainly doesn't seem to be a desirable
behavior. Ideally, the set_ylim (or set_xlim) would be respected as
well as the apect ratio and extra blank space around the figure would be
added as needed to fit the figsize.

By the way, using no figsize argument to subplots results in y limits
even smaller than the data limits. Also, this problem does not occur
for single (non-stacked) plots and the use of subplots_adjust also does
not seem to affect the problem. I'm using matplotlib 1.2.0

I did notice that this issue is similar to that discussed in this
thread:
http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg05783.html

Regards,
Jon

···

--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin@...1081... 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________

Hi all,

I've run across a minor but annoying bug. It can be demonstrated pretty
simply:

fig, ax = plt.subplots(2,1,sharex=True,figsize=(7.,7.))
fig.subplots_adjust(hspace=0.0)
x = 4.25*(np.arange(6.) - 2.5)/10.
y = 0.6*x/max(x)
ax[0].plot(x,y)
ax[0].set_xlim(-1.2,1.2)
ax[0].set_aspect('equal')
ax[1].plot(x,y)
ax[0].set_ylim(-0.6,0.6)
ax[1].set_ylim(-0.6,0.6)
ax[1].set_aspect('equal')
plt.show()

The problem is that the y limits on the two plots are slightly different
from those set:

I think the problem is that you are trying to specify too many things: you are specifying the box dimensions when you make the axes, then you are specifying xlim, and then you are specifying ylim, but then you are asking for a 1:1 aspect ratio. Something has to give! The aspect ratio handling is designed to provide the specified aspect ratio under a wide range of circumstances, including zooming and panning, and to do that, it has to be able to change something. You can choose to let the box dimensions be changeable, or the data limits.

If you want to fix the data limits, then you have to make the box adjustable. This can cause problems with shared axes, but you can try it with ax[0].set_aspect('equal', adjustable='box-forced').

Eric

···

On 2013/03/20 8:57 AM, Jonathan Slavin wrote:

ax[1].get_ylim()
(-0.61935483870967734, 0.61935483870967734)
and doing a set_ylim doesn't have any effect. This seems to be caused
by the set_aspect('equal'), since removing it results in plots with the
correct limits -- but aspect that is not quite equal. It is affected by
the figsize parameter in the call to subplots. It seems I can get the
correct y limits and aspect if I keep the set_aspect('equal') and fiddle
with the figsize. But that certainly doesn't seem to be a desirable
behavior. Ideally, the set_ylim (or set_xlim) would be respected as
well as the apect ratio and extra blank space around the figure would be
added as needed to fit the figsize.

By the way, using no figsize argument to subplots results in y limits
even smaller than the data limits. Also, this problem does not occur
for single (non-stacked) plots and the use of subplots_adjust also does
not seem to affect the problem. I'm using matplotlib 1.2.0

I did notice that this issue is similar to that discussed in this
thread:
[Matplotlib-users] strange axis limits behavior after using aspect_ratio

Regards,
Jon

Agree with Eric. I guess if you remove sharex=True, it will work.

Chao

···

On Wed, Mar 20, 2013 at 10:27 PM, Eric Firing [via matplotlib] <[hidden email]> wrote:

On 2013/03/20 8:57 AM, Jonathan Slavin wrote:

Hi all,

I’ve run across a minor but annoying bug. It can be demonstrated pretty

simply:

fig, ax = plt.subplots(2,1,sharex=True,figsize=(7.,7.))

fig.subplots_adjust(hspace=0.0)

x = 4.25*(np.arange(6.) - 2.5)/10.

y = 0.6*x/max(x)

ax[0].plot(x,y)

ax[0].set_xlim(-1.2,1.2)

ax[0].set_aspect(‘equal’)

ax[1].plot(x,y)

ax[0].set_ylim(-0.6,0.6)

ax[1].set_ylim(-0.6,0.6)

ax[1].set_aspect(‘equal’)

plt.show()

The problem is that the y limits on the two plots are slightly different

from those set:

I think the problem is that you are trying to specify too many things:
you are specifying the box dimensions when you make the axes, then you
are specifying xlim, and then you are specifying ylim, but then you are
asking for a 1:1 aspect ratio. Something has to give! The aspect ratio
handling is designed to provide the specified aspect ratio under a wide
range of circumstances, including zooming and panning, and to do that,
it has to be able to change something. You can choose to let the box
dimensions be changeable, or the data limits.

If you want to fix the data limits, then you have to make the box
adjustable. This can cause problems with shared axes, but you can try
it with ax[0].set_aspect(‘equal’, adjustable=‘box-forced’).

Eric

ax[1].get_ylim()

(-0.61935483870967734, 0.61935483870967734)

and doing a set_ylim doesn’t have any effect. This seems to be caused

by the set_aspect(‘equal’), since removing it results in plots with the

correct limits – but aspect that is not quite equal. It is affected by

the figsize parameter in the call to subplots. It seems I can get the

correct y limits and aspect if I keep the set_aspect(‘equal’) and fiddle

with the figsize. But that certainly doesn’t seem to be a desirable

behavior. Ideally, the set_ylim (or set_xlim) would be respected as

well as the apect ratio and extra blank space around the figure would be

added as needed to fit the figsize.

By the way, using no figsize argument to subplots results in y limits

even smaller than the data limits. Also, this problem does not occur

for single (non-stacked) plots and the use of subplots_adjust also does

not seem to affect the problem. I’m using matplotlib 1.2.0

I did notice that this issue is similar to that discussed in this

thread:

http://www.mail-archive.com/matplotlib-users@…83…/msg05783.html

Regards,

Jon


Everyone hates slow websites. So do we.

Make your web apps faster with AppDynamics

Download AppDynamics Lite for free today:

http://p.sf.net/sfu/appdyn_d2d_mar


Matplotlib-users mailing list

[hidden email]

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


If you reply to this email, your message will be added to the discussion below:

http://matplotlib.1069221.n5.nabble.com/set-limits-not-obeyed-for-stacked-plots-when-set-aspect-equal-used-tp40689p40690.html

To start a new topic under matplotlib - users, email [hidden email]

  To unsubscribe from matplotlib, click here.


  [NAML](http://matplotlib.1069221.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml)


Chao YUE
Laboratoire des Sciences du Climat et de l’Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex

Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16



View this message in context: Re: set limits not obeyed for stacked plots when set_aspect(‘equal’) used

Sent from the matplotlib - users mailing list archive at Nabble.com.

If I understand right, though, in this case what should give is the spacing around the axes but inside the figure (as suggested in the original post). You should be able to fix the aspect ratio of the *axes* and also the dimensions of the *figure*, and let the slack be taken up by blank space around the axes. It would still be possible for the dimensions of the axes box to change, just not their aspect ratio (i.e., zooming in on an oblong region would just result in a lot of blank space).

···

On 2013-03-20 14:25, Eric Firing wrote:

On 2013/03/20 8:57 AM, Jonathan Slavin wrote:

Hi all,

I've run across a minor but annoying bug. It can be demonstrated pretty
simply:

fig, ax = plt.subplots(2,1,sharex=True,figsize=(7.,7.))
fig.subplots_adjust(hspace=0.0)
x = 4.25*(np.arange(6.) - 2.5)/10.
y = 0.6*x/max(x)
ax[0].plot(x,y)
ax[0].set_xlim(-1.2,1.2)
ax[0].set_aspect('equal')
ax[1].plot(x,y)
ax[0].set_ylim(-0.6,0.6)
ax[1].set_ylim(-0.6,0.6)
ax[1].set_aspect('equal')
plt.show()

The problem is that the y limits on the two plots are slightly different
from those set:

I think the problem is that you are trying to specify too many things:
you are specifying the box dimensions when you make the axes, then you
are specifying xlim, and then you are specifying ylim, but then you are
asking for a 1:1 aspect ratio. Something has to give! The aspect ratio
handling is designed to provide the specified aspect ratio under a wide
range of circumstances, including zooming and panning, and to do that,
it has to be able to change something. You can choose to let the box
dimensions be changeable, or the data limits.

--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail."
    --author unknown

>> Hi all,

>> >>
>> >> I've run across a minor but annoying bug. It can be demonstrated pretty
>> >> simply:
>> >>
>> >> fig, ax = plt.subplots(2,1,sharex=True,figsize=(7.,7.))
>> >> fig.subplots_adjust(hspace=0.0)
>> >> x = 4.25*(np.arange(6.) - 2.5)/10.
>> >> y = 0.6*x/max(x)
>> >> ax[0].plot(x,y)
>> >> ax[0].set_xlim(-1.2,1.2)
>> >> ax[0].set_aspect('equal')
>> >> ax[1].plot(x,y)
>> >> ax[0].set_ylim(-0.6,0.6)
>> >> ax[1].set_ylim(-0.6,0.6)
>> >> ax[1].set_aspect('equal')
>> >> plt.show()
>> >>
>> >> The problem is that the y limits on the two plots are slightly different
>> >> from those set:
> >
> > I think the problem is that you are trying to specify too many things:
> > you are specifying the box dimensions when you make the axes, then you
> > are specifying xlim, and then you are specifying ylim, but then you are
> > asking for a 1:1 aspect ratio. Something has to give! The aspect ratio
> > handling is designed to provide the specified aspect ratio under a wide
> > range of circumstances, including zooming and panning, and to do that,
> > it has to be able to change something. You can choose to let the box
> > dimensions be changeable, or the data limits.

  If I understand right, though, in this case what should give is the
spacing around the axes but inside the figure (as suggested in the
original post). You should be able to fix the aspect ratio of the
*axes* and also the dimensions of the *figure*, and let the slack be
taken up by blank space around the axes. It would still be possible
for the dimensions of the axes box to change, just not their aspect
ratio (i.e., zooming in on an oblong region would just result in a lot
of blank space).

-- Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown

···

On 2013-03-20 14:25, Eric Firing wrote:
> > On 2013/03/20 8:57 AM, Jonathan Slavin wrote:

That is exactly what I suggested--use the kwarg adjustable='box-forced' when axes are shared. I think this will not work quite right for zooming and panning, which is the reason the normal adjustable='box' is rejected when axes are shared.

Eric

···

On 2013/03/20 3:16 PM, Brendan Barnwell wrote:

On 2013-03-20 14:25, Eric Firing wrote:

On 2013/03/20 8:57 AM, Jonathan Slavin wrote:

Hi all,

I've run across a minor but annoying bug. It can be demonstrated pretty
simply:

fig, ax = plt.subplots(2,1,sharex=True,figsize=(7.,7.))
fig.subplots_adjust(hspace=0.0)
x = 4.25*(np.arange(6.) - 2.5)/10.
y = 0.6*x/max(x)
ax[0].plot(x,y)
ax[0].set_xlim(-1.2,1.2)
ax[0].set_aspect('equal')
ax[1].plot(x,y)
ax[0].set_ylim(-0.6,0.6)
ax[1].set_ylim(-0.6,0.6)
ax[1].set_aspect('equal')
plt.show()

The problem is that the y limits on the two plots are slightly different
from those set:

I think the problem is that you are trying to specify too many things:
you are specifying the box dimensions when you make the axes, then you
are specifying xlim, and then you are specifying ylim, but then you are
asking for a 1:1 aspect ratio. Something has to give! The aspect ratio
handling is designed to provide the specified aspect ratio under a wide
range of circumstances, including zooming and panning, and to do that,
it has to be able to change something. You can choose to let the box
dimensions be changeable, or the data limits.

     If I understand right, though, in this case what should give is the
spacing around the axes but inside the figure (as suggested in the
original post). You should be able to fix the aspect ratio of the
*axes* and also the dimensions of the *figure*, and let the slack be
taken up by blank space around the axes. It would still be possible for
the dimensions of the axes box to change, just not their aspect ratio
(i.e., zooming in on an oblong region would just result in a lot of
blank space).

Eric,

I don't see it that way. Specifying an equal aspect ratio just means
that I want the scaling of the axes to the same. Then specifying the
data limits gives the overall scaling of the figure effectively. This
works perfectly well for a single set of axes. The bounding space is
allotted so that it all works. The problem only arises when I have the
figures stacked. Then it seems that the bounding space becomes fixed
for some reason and instead the axis limits are "what gives" instead of
the space around the axes.

By the way, the adjustable='box-forced' option to set_aspect generates
an exception,
ValueError: adjustable must be "datalim" for shared axes

Jon

···

On Wed, 2013-03-20 at 11:25 -1000, Eric Firing wrote:

On 2013/03/20 8:57 AM, Jonathan Slavin wrote:
> Hi all,
>
> I've run across a minor but annoying bug. It can be demonstrated pretty
> simply:
>
> fig, ax = plt.subplots(2,1,sharex=True,figsize=(7.,7.))
> fig.subplots_adjust(hspace=0.0)
> x = 4.25*(np.arange(6.) - 2.5)/10.
> y = 0.6*x/max(x)
> ax[0].plot(x,y)
> ax[0].set_xlim(-1.2,1.2)
> ax[0].set_aspect('equal')
> ax[1].plot(x,y)
> ax[0].set_ylim(-0.6,0.6)
> ax[1].set_ylim(-0.6,0.6)
> ax[1].set_aspect('equal')
> plt.show()
>
> The problem is that the y limits on the two plots are slightly different
> from those set:

I think the problem is that you are trying to specify too many things:
you are specifying the box dimensions when you make the axes, then you
are specifying xlim, and then you are specifying ylim, but then you are
asking for a 1:1 aspect ratio. Something has to give! The aspect ratio
handling is designed to provide the specified aspect ratio under a wide
range of circumstances, including zooming and panning, and to do that,
it has to be able to change something. You can choose to let the box
dimensions be changeable, or the data limits.

If you want to fix the data limits, then you have to make the box
adjustable. This can cause problems with shared axes, but you can try
it with ax[0].set_aspect('equal', adjustable='box-forced').

Eric

> ax[1].get_ylim()
> (-0.61935483870967734, 0.61935483870967734)
> and doing a set_ylim doesn't have any effect. This seems to be caused
> by the set_aspect('equal'), since removing it results in plots with the
> correct limits -- but aspect that is not quite equal. It is affected by
> the figsize parameter in the call to subplots. It seems I can get the
> correct y limits and aspect if I keep the set_aspect('equal') and fiddle
> with the figsize. But that certainly doesn't seem to be a desirable
> behavior. Ideally, the set_ylim (or set_xlim) would be respected as
> well as the apect ratio and extra blank space around the figure would be
> added as needed to fit the figsize.
>
> By the way, using no figsize argument to subplots results in y limits
> even smaller than the data limits. Also, this problem does not occur
> for single (non-stacked) plots and the use of subplots_adjust also does
> not seem to affect the problem. I'm using matplotlib 1.2.0
>
> I did notice that this issue is similar to that discussed in this
> thread:
> [Matplotlib-users] strange axis limits behavior after using aspect_ratio
>
> Regards,
> Jon
>

--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin@...1081... 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________

Hmm. It seems that the adjustable='box-forced' option to set_aspect
does work. I don't know what went wrong the first time I tried it
(probably a typo). So that solves my problem. Thanks Eric.

It does seem to me that this should be the default behavior, though I
can appreciate the difficulty with panning and zooming.

Jon

···

On Wed, 2013-03-20 at 18:16 -0700, Brendan Barnwell wrote:

On 2013-03-20 14:25, Eric Firing wrote:
> > On 2013/03/20 8:57 AM, Jonathan Slavin wrote:
>> >> Hi all,
>> >>
>> >> I've run across a minor but annoying bug. It can be
demonstrated pretty
>> >> simply:
>> >>
>> >> fig, ax = plt.subplots(2,1,sharex=True,figsize=(7.,7.))
>> >> fig.subplots_adjust(hspace=0.0)
>> >> x = 4.25*(np.arange(6.) - 2.5)/10.
>> >> y = 0.6*x/max(x)
>> >> ax[0].plot(x,y)
>> >> ax[0].set_xlim(-1.2,1.2)
>> >> ax[0].set_aspect('equal')
>> >> ax[1].plot(x,y)
>> >> ax[0].set_ylim(-0.6,0.6)
>> >> ax[1].set_ylim(-0.6,0.6)
>> >> ax[1].set_aspect('equal')
>> >> plt.show()
>> >>
>> >> The problem is that the y limits on the two plots are slightly
different
>> >> from those set:
> >
> > I think the problem is that you are trying to specify too many
things:
> > you are specifying the box dimensions when you make the axes,
then you
> > are specifying xlim, and then you are specifying ylim, but then
you are
> > asking for a 1:1 aspect ratio. Something has to give! The
aspect ratio
> > handling is designed to provide the specified aspect ratio under
a wide
> > range of circumstances, including zooming and panning, and to do
that,
> > it has to be able to change something. You can choose to let the box
> > dimensions be changeable, or the data limits.

  If I understand right, though, in this case what should give is the
spacing around the axes but inside the figure (as suggested in the
original post). You should be able to fix the aspect ratio of the
*axes* and also the dimensions of the *figure*, and let the slack be
taken up by blank space around the axes. It would still be possible
for the dimensions of the axes box to change, just not their aspect
ratio (i.e., zooming in on an oblong region would just result in a lot
of blank space).

-- Brendan Barnwell "Do not follow where the path may lead. Go,
instead, where there is no path, and leave a trail." --author unknown

--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin@...1081... 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________