From: Jody K. <jk...@uv...> - 2015-04-08 18:43:38
|
Hi Eric, > On 8 Apr 2015, at 11:02 AM, Eric Firing <ef...@ha...> wrote: > > I'm the guilty party for most of how set_aspect works. I developed it a > long time ago. Yes, there was a reason--still is, I'm 99% sure--but I > don't remember everything, and don't want to take the time now to > reconstruct the whole rationale. When I was developing the behavior, I > was paying a lot of attention to what happens under various scenarios of > resizing and reshaping the window, and turning options on and off. > There are some basic conflicts that arise when shared axes are combined > with fixed aspect ratios, autoscaling, and gui-driven reshaping. > Sometimes 'box-forced' does what people want, maybe more often than not; > but I'm pretty sure it can lead to trouble, which is the reason it is > not the default. OK, first my apologies: import matplotlib.pyplot as plt fig, axes = plt.subplots(nrows=2) axes[0].set_aspect(1.) axes[0].plot(np.arange(10),np.arange(10)) axes[0].set_ylim([0,24]) axes[0].set_xlim([0,12]) axes[1].plot(np.arange(10),np.arange(10)*2.) plt.show() Works as I'd expect. axes[0] gets shrunk in the x dimension to make the aspect ratio 1. However: import matplotlib.pyplot as plt fig, axes = plt.subplots(nrows=2,sharex=True) axes[0].set_aspect(1.) axes[0].plot(np.arange(10),np.arange(10)) axes[0].set_ylim([0,24]) axes[0].set_xlim([0,12]) axes[1].plot(np.arange(10),np.arange(10)*2.) plt.show() does not work as I'd expect. axes[0]'s ylim gets changed so that the line is no longer viewable (= 10-14). In my opinion, the two calls should work the same, except in the second case, axes[1]'s xlim should be 0-12. Even worse, if I use the same aspect ratio in axes[1], they *both* do not show all the data: axes[0].set_aspect(1.) It appears here that with sharex=True the shape of the axis no longer becomes mutable when set_aspect() is used, whereas if sharex=False set_aspect() can change the axis shape. I don't see any reason for sharex to foist this behaviour onto set_aspect(). I guess the workaround is don't use sharex=True, but I actually think this is a bug. Thanks, Jody -- Jody Klymak http://web.uvic.ca/~jklymak/ |