-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
2d plot titles #519
Conversation
title = [] | ||
for key, value in darray.coords.items(): | ||
if value.size == 1: | ||
title.append('{} = {}'.format(key, value.values)) |
There was a problem hiding this comment.
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))
@jhamman good idea 👍 |
@clarkfitzg - in your eyes, is this done? If so, I'll give it another look? |
@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(): |
There was a problem hiding this comment.
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):
...
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) |
There was a problem hiding this comment.
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.
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 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. |
Works for me. The error message should be informative enough in the other cases. Scalar coordinates- this is the current behavior:
So scalar coordinates do show up in the title, which is what I was going for. I could add a test for this.
That's the approach that I've moved to after spending more time on it. This PR adds the argument |
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): |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
feel free to merge |
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.