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

2d plot titles #519

Merged
merged 14 commits into from
Aug 12, 2015
Merged

2d plot titles #519

merged 14 commits into from
Aug 12, 2015

Conversation

clarkfitzg
Copy link
Member

Working on faceted plotting now. This will be helpful. It adds a title if the array came from a slice, and labels the colorbar with the variable name.

image

title = []
for key, value in darray.coords.items():
if value.size == 1:
title.append('{} = {}'.format(key, value.values))
Copy link
Member

Choose a reason for hiding this comment

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

don't you want to use integer placeholders for python 2.6?

title.append('{0} = {1}'.format(key, value.values))

@clarkfitzg
Copy link
Member Author

@jhamman good idea 👍

@jhamman
Copy link
Member

jhamman commented Aug 10, 2015

@clarkfitzg - in your eyes, is this done? If so, I'll give it another look?

@clarkfitzg
Copy link
Member Author

@jhamman Yes, ready for review.

If the dataarray comes from a slice we can show that info in the title
'''
title = []
for dim, coord in darray.coords.items():
Copy link
Member

Choose a reason for hiding this comment

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

use iteritems from core.pycompat:

for dim, coord in iteritems(darray.coords):
    ...

@clarkfitzg
Copy link
Member Author

Will finish this up tomorrow morning.

yincrease=yincrease, add_colorbar=add_colorbar,
vmin=vmin, vmax=vmax, cmap=cmap,
center=center, robust=robust, extend=extend,
levels=levels, **kwargs)
Copy link
Member Author

Choose a reason for hiding this comment

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

Changes here make it easier to keep the function / methods consistent.

@shoyer
Copy link
Member

shoyer commented Aug 12, 2015

For interactive use, I think plotting squeezed data is probably what users want. But I worry that this will make the result of plotting functions less predictable. Maybe we should restrict squeezing the data to only the magic DataArray.plot() method?

For axis titles, what happens if the data array has many scalar coordinates? Scalar coordinates can be directly assigned, not just created from indexing. My sense is that labelling facets will be more reliable if it is done explicitly in the same code that is doing the indexing/groupby.

@clarkfitzg
Copy link
Member Author

Maybe we should restrict squeezing the data to only the magic DataArray.plot() method?

Works for me. The error message should be informative enough in the other cases.

Scalar coordinates- this is the current behavior:

In [16]: a = xray.DataArray(np.random.randn(3, 4))

In [17]: a.coords['foo'] = 123

In [18]: a.plot()

image

So scalar coordinates do show up in the title, which is what I was going for. I could add a test for this.

labelling facets will be more reliable if it is done explicitly in the same code that is doing the indexing/groupby.

That's the approach that I've moved to after spending more time on it. This PR adds the argument add_labels to 2d plotting functions. Now for the faceting I'll actually use add_labels=False.

@shoyer
Copy link
Member

shoyer commented Aug 12, 2015

OK, seems pretty reasonable on the title then. Just note that some datasets (especially from model output) contain a lot of scalar variables, so that could easily get unwieldy. We might need to revisit this once it gets more use in the wild. For example, truncating the title at some reasonable line length might be a good idea.

@@ -1091,6 +1091,16 @@ def plot(self):
'''
return _PlotMethods(self)

def _title_for_slice(self):
Copy link
Member

Choose a reason for hiding this comment

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

To me, this logic seems more appropriate for a helper function in the plotting module (closer to where it is called).

Copy link
Member Author

Choose a reason for hiding this comment

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

Was waffling around where to put it. It's been in 3 different places over the course of this PR- here, in utils.py, and in the plot module. If you think the plot module is the best place then I'll put it there.

Copy link
Member

Choose a reason for hiding this comment

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

This is fine -- it doesn't matter very much

@shoyer
Copy link
Member

shoyer commented Aug 12, 2015

feel free to merge

clarkfitzg added a commit that referenced this pull request Aug 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants