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

Added a custom colour plotting example. #1040

Merged
merged 10 commits into from
Feb 28, 2014
Merged

Conversation

pp-mo
Copy link
Member

@pp-mo pp-mo commented Feb 24, 2014

No description provided.

========================

This example shows how to use custom colour schemes for anomaly plotting.
This demonstrates key techniques for using colour in matplotlib including:
Copy link

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:

@DPeterK
Copy link
Member

DPeterK commented Feb 24, 2014

My real problem with this can be summed up as tl;dr – that is to say, "too long; didn't read". The code goes on and on!!

So, I'm going to say it; I think this should be a notebook. That way you can introduce the colorbar-generating function log_color_controls at the top of the notebook and then split up all that code with each of the (very good) plots you generate. You could highlight the differences between the way you make each of the plots doing this, too.

)

# Make a pseudocolor plot using this continuous colour scheme.
mesh = iplt.pcolormesh(anomaly, cmap=anom_cmap, norm=anom_norm)
Copy link

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.

@cpelley
Copy link

cpelley commented Feb 24, 2014

So, I'm going to say it; I think this should be a notebook.

I agree with @dkillick, that this example is very long winded, but then it is illustrating lots of complexities.
I'm just wondering whether our users might give up on understanding whats going on before finding it useful.

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 log_color_controls will be used as a black-box function rather than understood.

@cpelley
Copy link

cpelley commented Feb 24, 2014

Turning the three plots within main() into three suitably named functions might increase readability too. Just a thought.
Over to you @pp-mo

@DPeterK
Copy link
Member

DPeterK commented Feb 24, 2014

I'm just wondering whether our users might give up on understanding whats going on before finding it useful.

This I think would be a benefit of making it a notebook - you can easier make the code into more bitesize chunks.

cautious that log_color_controls will be used as a black-box function

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')
Copy link
Member

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...

@pp-mo
Copy link
Member Author

pp-mo commented Feb 24, 2014

@dkillick 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)

I presume you mean http://matplotlib.org/examples/pylab_examples/custom_cmap.html ?
I'm just working that in ..

@pp-mo
Copy link
Member Author

pp-mo commented Feb 24, 2014

Thanks @cpelley @dkillick .
This hopefully addresses all the above specific comments. Please re-review.

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.

@DPeterK
Copy link
Member

DPeterK commented Feb 25, 2014

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.
Copy link
Member

Choose a reason for hiding this comment

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

Typo ("aconvenience")

@pp-mo
Copy link
Member Author

pp-mo commented Feb 25, 2014

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...

Thanks @dkillick .
I've tried to fix this now with an adjust_subplots call.
Please see if you approve (when it appears)...

@DPeterK
Copy link
Member

DPeterK commented Feb 25, 2014

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...

@ajdawson
Copy link
Member

We would typically only do that in a notebook as they have greater potential to not remain static. I'm not aware of any other gallery example that does this either...

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. iris.plot.pcolor etc.

@marqh
Copy link
Member

marqh commented Feb 26, 2014

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?

@pp-mo
Copy link
Member Author

pp-mo commented Feb 26, 2014

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.
In brief, I thought it did adversely impact the simplicity.
Following @marqh advice, I've since written a related contouring example, which in fact is significantly different (for reasons there explained).
Here : #1048

NOTE: clearly these two should reference one another, but we can't practically do that until the first one is merged.

@DPeterK
Copy link
Member

DPeterK commented Feb 27, 2014

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. iris.plot.pcolor etc.

@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
Copy link
Member

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!

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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 ...

@DPeterK
Copy link
Member

DPeterK commented Feb 27, 2014

OK, I'm 👍 for this now. Good job, @pp-mo!

@esc24
Copy link
Member

esc24 commented Feb 27, 2014

@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
Copy link
Member

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.

@esc24
Copy link
Member

esc24 commented Feb 27, 2014

All done. Over to you @pp-mo.

@pp-mo
Copy link
Member Author

pp-mo commented Feb 27, 2014

Thanks @esc24 some very smart ideas.
( I adopted all your suggestions, I think ! )
Please re-review.

All good, though it is a bit more verbose now, unfortunately.
Please suggest if you spot any ways to shorten it. I might have joined together some adjacent blocks of comment+code, but @cpelley already argued that a blank line before each comment is more readable, and I have come to agree with that.

@DPeterK
Copy link
Member

DPeterK commented Feb 28, 2014

Looking good...

esc24 added a commit that referenced this pull request Feb 28, 2014
Added a custom colour plotting example.
@esc24 esc24 merged commit ce95c41 into SciTools:master Feb 28, 2014
@DPeterK
Copy link
Member

DPeterK commented Feb 28, 2014

🎉 Good stuff.

@pp-mo
Copy link
Member Author

pp-mo commented Feb 28, 2014

Final apologies for taking so long to bring this under control.
Serious learning point: I should have fixed more realistic goals much sooner, but was too committed to admit the need !
Thanks to everyone : @dkillick @cpelley @ajdawson @marqh @esc24 for staying the course.

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.

7 participants