-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Better auto-selection of axis limits #4891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
(See also) |
margins already has an rcparam. |
Okay, having done a bit of reading, it sounds like: there are rcParams Specifically, I see two obvious options: either switch the meaning of the existing rcParams so that they imply |
Although I dislike the ever-increasing number of rcParams, it looks to On 8/8/15, Nathaniel J. Smith notifications@github.com wrote:
|
I am in favor of less magic in picking the x and y margins (I think that is On Sat, Aug 8, 2015 at 9:33 PM, Nathaniel J. Smith <notifications@github.com
Brian E. Granger |
Okay, so looking at axes/_base.py it seems that we currently have the following terminology:
Then when we autoscale, the rules are:
I guess what we want for a default is something like: if the plot contains something besides an image, then apply the margins only; otherwise, do nothing. This means that maintaining strict backwards compatibility is going to be tricky -- potentially people are currently using margins with images, or using margins together with custom locators with custom |
Just as a clarification here, we're only talking about changing what the i.e.
If so, great! Of course, the caveats about actually making it work as an rcParam while allowing full backwards compatibility are tough. I do think an rcParam that's equivalent to calling However, I'd argue for against making In my experience, "even numbers" are desirable as axes limits about as often as a percentage padding is. In some cases you want one, in some cases the other. Given that it's roughly 50/50 split (though, again, that's just my opinion), it's best to stick with what we have. In my opinion, the main problem is that too few people are aware of I don't think it's worth grossly breaking backwards compatibility for something that's better solved by ensuring people are aware of Overall, line plots are the most common case where autoscaling with even numbers makes the most sense. (Feel free to argue the contrary there!) They're also probably the most common plot type. I don't think that it's worth breaking that expectation for something that's easy to fix in the cases where you don't want "even-number" autoscaling. For example, the most frequently asked question I've seen about autoscaling involves bar plots. The default autoscaling is the best choice for This is a classic case where even-number-choosing as limits is not optimal. However, I would argue it's far easier to fix this by letting people know about For example, with a vertical bar plot, you'll often want a combination of
However, in my experience, surprisingly few people are aware that it's possible to create the bottom plot without using manually set axes limits. Overall, I'd argue the bigger problem is that the examples almost never show little things such as this. (I know, I know, PR's welcome!). We can better solve the problem with better advertising of existing functionality instead of breaking backwards compatibility for what's basically a 50/50 advantage/disadvantage. Just my thoughts on the matter, anyway. I definitely think it's a good discussion to have, regardless! |
This is the first time I hear about |
The argument against "round number" autoscaling is that sometimes it works fine, and sometimes it fails utterly and produces awful plots (see the examples cited at the top of this thread, which all involve line plots, or your bar plot example). Simple margins OTOH may or may not be the absolute prettiest, but they always work. When choosing defaults IMO the focus shouldn't be on the best cases, but on the worst cases -- if some rule produces 5% better plots 50% of the time and terrible plots the rest of the time, then it's a bad default. |
@njsmith - That's actually a really good point. A good default should have few downsides. By that logic, margins-style autoscaling is a better default. Consider me won-over. |
@joferkington: That's was @tacaswell and I also came to at our "style summit" today, so with good certainty that's what the default will be in 2.0 |
As discussed at the matplotlib 2.0 BoF, it would be good to switch the method for default selection of axis limits to something a little less magical. Right now, it does something like: pick the nearest "round number" that is outside of all the data. But this leads to all kinds of weirdnesses. For example:
spectral distributionautocorrelation function of white noise (a plot that I've actually used in papers):plt.plot(np.linspace(0, 1, 1000), [1] + [0] * 999)
. Or if you have a scatter plot, the scatter markers may be half off-screen. A very minimal requirement for a default plotting method is that it should show all the data.plt.plot(np.random.randn(256))
. Notice that this gives x-axis limits of(0, 300)
and looks ridiculous.The easiest way to handle this is to simply ensure that the axis limits are slightly larger than necessary to cover all the data, and then leave it at that. It avoids the really nasty cases, avoids surprises, and if people want something fancier than they almost always have to tweak the limits by hand anyway. As further evidence that this works, this is what R does and it basically just works -- no-one complains.
Specifically, base R calculates default axis limits by: taking the min and max of the data, and then setting the limits 4% further beyond each of those. ggplot2 uses a similar algorithm, but uses 5% by default. (See here, semantics of
expand=
is (multiplicative expansion, additive expansion).)This is an issue instead of a PR because I'm not sure how to make this a PR :-). At the BoF someone said that the suggested functionality was already in matplotlib as something called "margins"? But I'm not sure what that is or how to hook it up to rcParams.
The text was updated successfully, but these errors were encountered: