-
Notifications
You must be signed in to change notification settings - Fork 283
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
Added a custom colour plotting example. #1040
Conversation
======================== | ||
|
||
This example shows how to use custom colour schemes for anomaly plotting. | ||
This demonstrates key techniques for using colour in matplotlib including: |
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.
Repeat of this
and repeat of colour
Change to:
This example shows how to use custom colour schemes for anomaly plotting, demonstrating key techniques using Matplotlib, including:
My real problem with this can be summed up as So, I'm going to say it; I think this should be a notebook. That way you can introduce the colorbar-generating function |
) | ||
|
||
# Make a pseudocolor plot using this continuous colour scheme. | ||
mesh = iplt.pcolormesh(anomaly, cmap=anom_cmap, norm=anom_norm) |
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.
Might be worth making these subplots, then each image won't appear as its own separate gallery example image.
I agree with @dkillick, that this example is very long winded, but then it is illustrating lots of complexities. Not sure I see a way around this though since colourmaps in matplotlib are a difficult thing to get into. I am also cautious that |
Turning the three plots within main() into three suitably named functions might increase readability too. Just a thought. |
This I think would be a benefit of making it a notebook - you can easier make the code into more bitesize chunks.
Agreed. I reckon that by making lines 72-79 much less obtuse by documenting them a little more (even by linking to the matplotlib gallery example that does just that) might well persuade our users to not treat it as a black box but instead given them empowerment to write their own function to do more precisely what they want rather than using this with fudge factors. |
|
||
# Make a pseudocolor plot using this continuous colour scheme. | ||
mesh = iplt.pcolormesh(anomaly, cmap=anom_cmap, norm=anom_norm) | ||
bar = plt.colorbar(mesh, orientation='horizontal', extend='both') |
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.
If you're going to extend it would be nice to have a discrete colour for them, so that you can differentiate between elements that fall within and without of the colorbar's range...
I presume you mean http://matplotlib.org/examples/pylab_examples/custom_cmap.html ? |
Thanks @cpelley @dkillick . However, I certainly do agree this is still rather verbose and complex. I'm really trying to make the best of this here, and see if it can be made into an acceptable gallery example, simply because I still think that is a preferable dissemination route, if it can be squeezed into that format. That's especially while we still don't have general notebooks usage within the office. If after our best efforts it is still too awkward, then we could still choose to recast it as a notebook example. |
Now that you've turned your images into a single image of three subplots in a row it is far too wide for the webpage - even on high-res monitors it is flowing off the right of the screen... |
plt.title(title) | ||
|
||
|
||
# Define aconvenience function for making a filled-contour plot. |
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.
Typo ("aconvenience")
Thanks @dkillick . |
It is going to be a tricky one to sort I think - it will always be quite a wide image so is almost certain to flow off the right of the page under some circumstances. I'd suggest you make them into three separate images again but I know that @cpelley asked for them to be combined... |
I think we have a crossed wire @dkillick, I didn't mean say what version of Iris was used, I meant reference the iris versions of pcolor instead of just the matplotlib ones, i.e. |
this looks good to me, I think this is a really useful example. If (and only if) it doesn't adversely impact the simplicity, I think it would be helpful to show how a similar contourf plot would be constructed using complementary colour representation. In particular, how to set the levels such that the 'white in the middle' is a contour level and there are a fixed number either side. perhaps having two clear examples side by side in the gallery could deliver this? |
Thanks @marqh. NOTE: clearly these two should reference one another, but we can't practically do that until the first one is merged. |
@ajdawson I see! In the context I took "Iris versions" to mean something a little different 😄 @pp-mo I think that this is actually a good point; it seems a little spurious to reference the matplotlib versions of Iris plotting functions in an Iris example... |
We use this to make a cell-filled pseudocolour plot with a colorbar. | ||
|
||
NOTE: By "pseudocolour", we mean that each data point is drawn as a "cell" | ||
region on the plot, coloured according to its data value. In matplotlib, this |
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 really should be "In Iris, this is done with..." – that's the whole point of these examples!
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.
No, I really disagree. All of the techniques here are generic to matplotlib, and have no dependency on Iris or Cartopy, which is why I initially did not even mention the Iris forms of the plot functions, which @ajdawson then asked for.
In my experience, It has been a major education issue from the start of this project that most of our users do not appreciate which features come from which modules/projects, so I really don't want to add the tiniest part to that confusion.
I did raise the point on Monday that I was uncomfortable that this example had nothing specific to to Iris or Cartopy in it, but "it is just matplotlib". But several people (@marqh @rhattersley -- and I think even yourself @dkillick ?) said there was nothing wrong with that.
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.
If it has nothing to do with Iris then you should either be submitting this example to matplotlib or not submitting it at all. As it is, it is an Iris example in the Iris gallery that demonstrates how to improve an Iris plot of data loaded into Iris. The fact that you go on to use Iris plotting functions and not matplotlib ones adds to this fact. Many of our end users will not care about the fact that Iris plotting functions are wrapped matplotlib ones, so I think you run the risk of confusing the matter further by introducing matplotlib functions that you then do not use in the example.
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.
Some disagreement here still, resolved offline with @dkillick leading to upcoming proposals ...
OK, I'm 👍 for this now. Good job, @pp-mo! |
@dkillick asked me to merge this, but I have a few comments I feel need addressing first. Here goes... |
temperatures = iris.load_cube(file_path) | ||
|
||
# Create a sample anomaly field for one year, by subtracting a time mean. | ||
i_year = 122 |
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.
I'm not keen on encouraging indexing for this type of operation. It can make brittle code that fails silently or unexpectedly. How about using coord_categorisation here to add a year coord? e.g.
import iris.coord_categorisation
iris.coord_categorisation.add_year(temperatures, 'time')
time_mean = temperatures.collapsed('time', iris.analysis.MEAN)
anomaly = temperatures - time_mean
year = 1982
specific_year_anomoly = anomolies.extract(iris.Constraint(year=year))
It's a simple opportunity to demonstrate and encourage this approach. You can then use year
and time_mean.coord('year').bounds[0]
to get the values for the title.
All done. Over to you @pp-mo. |
Thanks @esc24 some very smart ideas. All good, though it is a bit more verbose now, unfortunately. |
Looking good... |
Added a custom colour plotting example.
🎉 Good stuff. |
No description provided.