Skip to content
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

feature request: scale extents a bit more than the absolute fit #1090

Closed
basnijholt opened this issue Jan 30, 2017 · 21 comments
Closed

feature request: scale extents a bit more than the absolute fit #1090

basnijholt opened this issue Jan 30, 2017 · 21 comments
Assignees
Labels
type: feature A major new feature
Milestone

Comments

@basnijholt
Copy link
Contributor

Right now:

hv.Scatter([[-1,-1], [-1, 1], [0, 1], [1,1]])

gives points that you cannot even see:
download

Preferably the plot would take the extent and make it 10% bigger or so, like:

hv.Scatter([[-1,-1], [-1, 1], [0, 1], [1,1]])[-1.1:1.1, -1.1:1.1]

which does show the points:
download 1

@philippjfr
Copy link
Member

philippjfr commented Jan 30, 2017

Agreed, this is something we should have added a long time ago. All our plots should automatically pad the axis ranges by a few percent. The question has always been how precisely the padding is calculated. Is it a fixed 10% or is there special handling around zero? Other plotting libraries have had this discussion (see matplotlib/matplotlib#4891) and have generally settled on a fixed 4-5% padding along each axis:

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).)

If we agree with both matplotlib and ggplot2 (and bokeh?) that's what we can use by default as well. It's trivial to do and I strongly believe this belongs in 1.7 as part of changing our global styling defaults (#823).

@philippjfr philippjfr added this to the v1.7.0 milestone Jan 30, 2017
@philippjfr philippjfr added the type: feature A major new feature label Jan 30, 2017
@jbednar
Copy link
Member

jbednar commented Jan 30, 2017

I agree.

@jlstevens
Copy link
Contributor

I think this is a good idea and I agree that we should use someone else's magic value for this parameter (and stick to it). My preference for conventions would be to follow that matplotlib does, then bokeh and then ggplot2.

@philippjfr
Copy link
Member

They all do the same thing 5% padding on each end of an axis.

@jbednar
Copy link
Member

jbednar commented Jan 30, 2017

5% it is, then!

@philippjfr
Copy link
Member

Note that I do not want to add automatic padding to raster types because it's ugly. Therefore I'd suggest a plot option, which has different defaults for chart and raster plots. The difficulty then is figuring out what happens when overlaying the two. I'd suggest the bottom layer determines the padding since that will usually be the raster type.

@jlstevens
Copy link
Contributor

I would be tempted to say that if there is any raster type in the overlay, don't apply any padding.

@jbednar
Copy link
Member

jbednar commented Feb 1, 2017

Either of those two policies seems fine, as long as we choose it and stick with it. Whichever one seems more consistent with other things we do where one layer needs to determine the overall behavior.

Presumably a GeoViews tile source wouldn't count as a raster, for this purpose? Those generally have effectively infinite extent, and thus expanding to show the points or box seems appropriate.

@philippjfr
Copy link
Member

Let's try implementing this for 1.7, setting the margin parameter to zero and then add some default padding in 2.0.

@philippjfr philippjfr self-assigned this Mar 15, 2017
@jbednar
Copy link
Member

jbednar commented Mar 15, 2017

Sounds like a good plan. Do we want to make a 2.0 branch now, to include these breaking changes, that we keep rebasing as needed, so that we can try out the new version in practice? If it's just a parameter change as in this case, seems like such rebasing will be simple.

@philippjfr
Copy link
Member

Sounds good, I'll open one as soon as there is a breaking change I can apply to it.

@jbednar
Copy link
Member

jbednar commented Mar 15, 2017

Changing the default colormap could be the first one. :-)

@philippjfr
Copy link
Member

So this turns out to be a bit more complex than anticipated. The main question is what this should apply to, we have the data ranges, explicitly set ranges and extents. Presumably it should not apply to explicitly set values, but currently we have no way of distinguishing a Dimension.range from a data range and the get_extents method in plotting and the normalization system are not set up to handle the distinction between the two. The other complication are log axes where computing padding requires some transforms.

At minimum this will require #1212 to be implemented but probably requires at least a partial rewrite of range handling in general. I'm unfortunately going to have to postpone this until 2.0.

@philippjfr philippjfr modified the milestones: v2.0, v1.7.0 Apr 12, 2017
@philippjfr philippjfr modified the milestones: v2.0, v1.10 Dec 8, 2017
@philippjfr philippjfr modified the milestones: v1.10, v1.11 Mar 19, 2018
@philippjfr
Copy link
Member

This has finally been merged, we should however decide whether to enable padding by default in 1.11 or wait on another release and pre-announce the change as part of the 1.11 release notes.

@philippjfr
Copy link
Member

We have definitely decided not to enable this by default in 1.11.

@philippjfr philippjfr reopened this Jan 17, 2019
@philippjfr philippjfr modified the milestones: v1.11.0, v1.12.0 Jan 17, 2019
@philippjfr philippjfr modified the milestones: v1.12.0, v1.12.x Apr 22, 2019
@jlstevens
Copy link
Contributor

@philippjfr @jbednar I assume it is now time to switch this on immediately after the upcoming release?

I assume the diff will be to set this value to 0.05. To achieve 5% padding. Then we can add something in the release notes to help people set it back to zero if they want to restore the old behavior.

@philippjfr
Copy link
Member

I assume the diff will be to set this value to 0.05

Not sure, I usually use 0.1 for 5% padding on each end.

@philippjfr philippjfr modified the milestones: v1.12.x, v1.13.0 Oct 2, 2019
@SandervandenOord
Copy link

I hope padding can be added as a default in one of the upcoming releases, as I find myself continuously setting xlim and ylim manually.

@basnijholt
Copy link
Contributor Author

basnijholt commented Jan 15, 2020

Happy we were able to close this with a successful end 3 years later 😂 🎉

@SandervandenOord
Copy link

I just tested this with the newest holoviews for scatter and bar. Works nice. What a difference a little bit of padding makes for the way plots look :)

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature A major new feature
Projects
None yet
Development

No branches or pull requests

5 participants