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

ENH: more control on colorbar #872

Merged
merged 3 commits into from
Jun 9, 2016
Merged

Conversation

fmaussion
Copy link
Member

Addresses #752 and allows to pass kwargs to colorbar. For example, it is now possible to do:

import numpy as np
import matplotlib.pyplot as plt
import xarray as xr

x, y = np.meshgrid(np.arange(12), np.arange(12))
z = xr.DataArray(np.sqrt(x**2 + y**2))
ds = z.to_dataset(name='z')

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(12, 12))
ds.z.plot.contourf(ax=ax1)
ds.z.plot.contourf(ax=ax2, cbar_kwargs={'orientation':'horizontal', 'label':'MyLabel'})
ds.z.plot.contourf(ax=ax3, cbar_ax=ax4, cbar_kwargs={'orientation':'horizontal',
                                                     'label':'Funny Cbar',
                                                     'drawedges':True})
plt.tight_layout()
plt.show()

test_cbar

@shoyer
Copy link
Member

shoyer commented Jun 8, 2016

This looks great -- it is possible to add a test for some of this functionality? Take a look at the existing plotting tests and see if there's anything you can do easily.

else:
cbar_kwargs.setdefault('cax', cbar_ax)
cbar = plt.colorbar(primitive, **cbar_kwargs)
if darray.name and add_labels and 'label' not in cbar_kwargs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one corner case that may require checking is when add_colorbar = False and cbar_ax or cbar_kwargs is specified. It might be worth checking and just raising an error. Unless you can think of a time when you want to be able to specify arguments that aren't used.

@jhamman
Copy link
Member

jhamman commented Jun 9, 2016

This is great. I had two small comments and agree that it could use some tests.

@fmaussion
Copy link
Member Author

@shoyer I added some tests and and implemented @jhamman 's comments. I am not a big fan of raising an error when keywords are set and not used, but I don't have a use case for this either so I implemented it as requested ;)

@shoyer
Copy link
Member

shoyer commented Jun 9, 2016

This looks great. We just need a brief note for what's new now.

@fmaussion
Copy link
Member Author

Right, I always forget about this one. Let me know if I should rebase, too.

@jhamman
Copy link
Member

jhamman commented Jun 9, 2016

No need to rebase. We can squash on the github side now.

@fmaussion
Copy link
Member Author

fmaussion commented Jun 9, 2016

Yes, ok.

[OT]: Some people on the mpl mailing list said it was a dangerous feature of github but I didn't understand why. I guess that for large PRs it might be useful to keep the intermediate commits, but for the majority of the cases it makes the git history much clearer I think.

@shoyer
Copy link
Member

shoyer commented Jun 9, 2016

Yeah, I'm a big fan of squash-on-merge. It's much easier than forcing contributors to master git rebase.

@shoyer shoyer merged commit 450ac8f into pydata:master Jun 9, 2016
@shoyer
Copy link
Member

shoyer commented Jun 9, 2016

Thanks @fmaussion !

@rvalenzuelar
Copy link

Could you give an example on how to use this functionality when using faceting plots? For example, I have a 4 column figure and I would like to have the colorbar on top.

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

Successfully merging this pull request may close these issues.

4 participants