Skip to content

significance of the number 14 in calls to contour and tricontour? #12762

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

Closed
Phillip-M-Feldman opened this issue Nov 7, 2018 · 9 comments
Closed
Labels
Milestone

Comments

@Phillip-M-Feldman
Copy link

I'm looking at the page at this URL:

https://matplotlib.org/gallery/images_contours_and_fields/irregulardatagrid.html#sphx-glr-gallery-images-contours-and-fields-irregulardatagrid-py

What is the significance of the number 14 in calls to contour and tricontour? (I know that this is a lucky number of have at table, but am wondering if there is some other reason for this value).

@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commented Nov 7, 2018

You're asking about ax.contour(x, y, z, 14), right? This is the "nominal" number of levels to use in the contouring. Unfortunately, the documentation is wrong with respect to this argument, as we've just found out.

Hence I'd call it "nominal" for now. As can be seen from the colorbar there are 15 contour regions, separated by 14 inner edges. If you were to choose a different number of levels, e.g. 9 instead of 14, you'd see 9 contoured regions in the plot

image

If you need full control over the number of levels, or even the actual numeric values, you may plug in a list of edge values, e.g. ax.contour(xi, yi, zi, numpy.linspace(-.5, +.5, 21)) (21 edges, hence 20 contour regions; but not all of them are present in the plot, because the data does not range up to 0.5).

image

As to why the this example takes precisely 14 here, I can't remember. In a previous version of it, there were 15 levels being used. Then the example got lost. Then I revived it and for a reason I cannot recall, used 14 levels.
It shouldn't actually matter, but if anyone has an argument for why possibly a different number should be used here, we can also change it.

@Phillip-M-Feldman
Copy link
Author

Phillip-M-Feldman commented Nov 9, 2018 via email

@ImportanceOfBeingErnest
Copy link
Member

I cannot reproduce the error. But you did not mention which versions you are using.

In general, I guess even if you use a Mercator projection for the axes, the artist transform should still be a PlateCarree, as the data is defined in the 0, 360 / -90 90 range.

ax= fig.add_subplot(1, 1, 1, projection=crs.Mercator())
ax.contourf(lons, lats, data, transform=crs.PlateCarree(), levels=20, cmap='nipy_spectral')

@Phillip-M-Feldman
Copy link
Author

Phillip-M-Feldman commented Nov 9, 2018 via email

@jklymak jklymak added the Community support Users in need of help. label Nov 9, 2018
@ImportanceOfBeingErnest
Copy link
Member

This has been fixed by #11917. It'll work fine with matplotlib 3.0.0 or higher.

#11917 has not been backported to the 2.x branch. Would that make sense in view of this?

@ImportanceOfBeingErnest
Copy link
Member

I see clear now. 😎
In matplotlib < 3, levels did not actually take an integer although the documentation of 2.2.3 claimed that to be the case. So in 2.2.3 or below you need

ax.contourf(lons, lats, data, 20, cmap='nipy_spectral')

while in 3.0.0 or higher you can equally do

ax.contourf(lons, lats, data, levels=20, cmap='nipy_spectral')

So, one could either change the documentation in the 2.x branch, or backport #11917 or forget about it, since the examples are all correct.

@timhoffm
Copy link
Member

I don't see so clearly 😃.

One should do something on 2.2.x to get it's behavior and doc in sync.
If #11917 does only add the support for using levels as kwarg, then I'm +1 on backporting. If on the other hand, it also changes the figure generated with the positional arguement form, we should just update the docs.

@anntzer
Copy link
Contributor

anntzer commented Jul 3, 2019

Remilestoning as 2.2.x (#12762 (comment)) given that on master the example already reads levels=14.

@timhoffm
Copy link
Member

This has already been backported in #11917.

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

No branches or pull requests

7 participants