Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Better auto-selection of axis limits #4891

Closed
Assignees
mdboom
Milestone
@njsmith

Description

@njsmith

Asdiscussed 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:

  • If your data goes from 0 to 1, then your limits will be from 0 to 1. Which means that data which actually falls right at 0 or 1 may be obscured by the axis limits -- e.g., here's thespectral distribution autocorrelation 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 adefault plotting method is that it shouldshow all the data.
  • If your datadoesn't go between some nice round numbers (which is very common), then you can get very ugly, asymmetric graphs. E.g. because of how the FFT works, it's not uncommon when working with signals to want to e.g. plot a spectrum with 256 elements: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 ofexpand= 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp