Skip to content

colorbars in facet grids #1717

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

Closed
JoyMonteiro opened this issue Nov 15, 2017 · 6 comments · Fixed by #2444
Closed

colorbars in facet grids #1717

JoyMonteiro opened this issue Nov 15, 2017 · 6 comments · Fixed by #2444

Comments

@JoyMonteiro
Copy link

Hello,

In the 0.9.6 version, it does not appear to be possible to pass any arguments to the colorbar plotting
routine.

func_kwargs.update({'add_colorbar': False, 'add_labels': False})

explicitly sets set_colorbar = False, which makes sense.

However, if we want horizontal colorbars, or any way of adjusting the colorbar plotted (it is huge and unwieldy), it would be good if the plotting routine checks for and passes suitable arguments to

self.add_colorbar()

I tried hacking something together, I can do something like the following now:

import xarray
import matplotlib.pyplot as plt

data = xarray.open_dataset('/data/ERSST/sst.mnmean.old.nc').sst

data = data.loc[dict(time=slice('1999-1', '1999-4'))]
data.plot.contourf(col='time', col_wrap=2, levels=12, cbar_kwargs=dict(orientation='horizontal',
                                                pad=0.1, aspect=30, shrink=0.6, ticks=[0, 10, 20 ,30]))

which produces:

figure_1

Is something like this available in the development version? If not, and it seems like a useful feature, I can create a PR.

Joy

@shoyer
Copy link
Member

shoyer commented Nov 20, 2017

I don't think we have anything like this in the development version yet.

I wonder if it would be better to stop plotting colorbars automatically, and instead require explicitly calling add_colorbar()?

@fmaussion
Copy link
Member

What are the arguments against cbar_kwargs ? This would be consistent with the API of the other 2D plots

@shoyer
Copy link
Member

shoyer commented Nov 20, 2017

Indeed, for consistency it would make sense to add cbar_kwargs. I'm just thinking that going forward (if we can solve the backwards compatibility problem) it might be cleaner to avoid making a color-bar automatically in the same call to .plot().

@fmaussion
Copy link
Member

it might be cleaner to avoid making a color-bar automatically in the same call to .plot()

For all 2D plots or just for facetgrids? In general I like the all-in-one feeling of xarray plots currently, and I imagine that the automatic colorbar is used very often.

@shoyer
Copy link
Member

shoyer commented Nov 20, 2017 via email

@JoyMonteiro
Copy link
Author

Great, will prepare a PR! I second @fmaussion on keeping the auto colorbar, just makes life easy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants