Title: Better auto-selection of axis limits · Issue #4891 · matplotlib/matplotlib · GitHub
Open Graph Title: Better auto-selection of axis limits · Issue #4891 · matplotlib/matplotlib
X Title: Better auto-selection of axis limits · Issue #4891 · matplotlib/matplotlib
Description: 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 ...
Open Graph Description: 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 ne...
X Description: 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 ne...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/4891
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Better auto-selection of axis limits","articleBody":"As [discussed at the matplotlib 2.0 BoF](https://docs.google.com/document/d/1ftNmQn7QVr6m2mkgVYTd_0eTA_o7vn9t3sliVp9cKOw), 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:\n- 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 the ~~spectral 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 a _default_ plotting method is that it should _show all the data_.\n- If your data _doesn'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.\n\nThe 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.\n\nSpecifically, 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](http://www.inside-r.org/packages/cran/ggplot2/docs/scale_continuous), semantics of `expand=` is (multiplicative expansion, additive expansion).)\n\nThis 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.\n","author":{"url":"https://github.com/njsmith","@type":"Person","name":"njsmith"},"datePublished":"2015-08-09T03:17:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/4891/matplotlib/issues/4891"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4d830710-936b-a9d0-86fe-5fdac6382087 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E32C:2D4C32:D3B34:11B38E:6A52BA46 |
| html-safe-nonce | e680b5d40659f045680664c35cbc9048af9267c613f2c72f8410ac879bf9f3d8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzJDOjJENEMzMjpEM0IzNDoxMUIzOEU6NkE1MkJBNDYiLCJ2aXNpdG9yX2lkIjoiNTk3ODMwNDE5Mzg2MTE3MTc4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4abde513aed5433338e8cf6dcb827233ab4e84aeb036589541274dd3e19cfbca |
| hovercard-subject-tag | issue:99857479 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/4891/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eadfe6ab343a687638c2304d32df33ea16ee7174a35bfdf754b74b037c505122/matplotlib/matplotlib/issues/4891 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eadfe6ab343a687638c2304d32df33ea16ee7174a35bfdf754b74b037c505122/matplotlib/matplotlib/issues/4891 |
| og:image:alt | 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 ne... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | njsmith |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width