Skip to content

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

Closed

Description

@Phillip-M-Feldman

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

Activity

  1. ImportanceOfBeingErnest commented on Nov 7, 2018

    @ImportanceOfBeingErnest
    Member

    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.

  2. added this to the v3.0.0-doc milestone on Nov 7, 2018
  3. Phillip-M-Feldman commented on Nov 9, 2018

    @Phillip-M-Feldman
    Author
  4. ImportanceOfBeingErnest commented on Nov 9, 2018

    @ImportanceOfBeingErnest
    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')
    
  5. Phillip-M-Feldman commented on Nov 9, 2018

    @Phillip-M-Feldman
    Author
  6. ImportanceOfBeingErnest commented on Nov 9, 2018

    @ImportanceOfBeingErnest
    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?

  7. ImportanceOfBeingErnest commented on Nov 10, 2018

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

  8. timhoffm commented on Nov 18, 2018

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

  9. modified the milestones: v3.0.0-doc, v3.0.2-doc on Nov 27, 2018
  10. modified the milestones: v3.0-doc, v3.1-doc on Jul 3, 2019
  11. modified the milestones: v3.1-doc, v2.2.5 on Jul 3, 2019
  12. anntzer commented on Jul 3, 2019

    @anntzer
    Contributor

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

  13. timhoffm commented on Jul 21, 2019

    @timhoffm
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions