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

Contours not displaying properly with matplotlib 3.8 #5899

Closed
ktyle opened this issue Sep 21, 2023 · 2 comments · Fixed by #5910
Closed

Contours not displaying properly with matplotlib 3.8 #5899

ktyle opened this issue Sep 21, 2023 · 2 comments · Fixed by #5910
Assignees
Labels
type: bug Something isn't correct or isn't working

Comments

@ktyle
Copy link

ktyle commented Sep 21, 2023

In an environment running an up-to-date Holoviz set of packages:

geoviews = 1.10.1
holoviews = 1.17.1
bokeh = 3.2.2
panel = 1.2.3

I’ve discovered that both line and filled contours do not properly display if Matplotlib 3.8.0 is installed. Things work properly with MPL 3.7.3.

Here is a fully-reproducible code block:

import geoviews as gv
import xarray as xr

gv.extension("bokeh")

Z = xr.open_dataset(
    "http://thredds.atmos.albany.edu:8080/thredds/dodsC/atm533/2012103000_z500_era5.nc"
).z

gv.LineContours(Z.isel(time=0), kdims=["longitude", "latitude"], vdims=["z"])

Here are a couple of screenshots (with a background map layer) showing the expected (pre-MPL 3.8) and problematic (MPL 3.8.0) visualizations:

Good (MPL 3.7.3):
Geoviews_MPL373

Problematic (MPL 3.8.0):
Geoviews_MPL380

@ahuang11
Copy link
Collaborator

Copying my thoughts from https://discourse.holoviz.org/t/contours-not-displaying-properly-with-matplotlib-3-8/6068/4

I suppose it's a HoloViews issue actually: https://holoviews.org/_modules/holoviews/operation/element.html#contours

    def _process(self, element, key=None):
        try:
            from matplotlib.contour import QuadContourSet
            from matplotlib.axes import Axes
            from matplotlib.figure import Figure
            from matplotlib.dates import num2date, date2num
        except ImportError:
            raise ImportError("contours operation requires matplotlib.")
        extent = element.range(0) + element.range(1)[::-1]

Or perhaps a matplotlib issue since we're just using QuadContourSet?

Or because of this:
https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.8.0.html#contourset-is-now-a-single-collection

And we need to loop differently:

Prior to this release, ContourSet (the object returned by contour) was a custom object holding multiple Collections (and not an Artist) -- one collection per level, each connected component of that level's contour being an entry in the corresponding collection.

ContourSet is now instead a plain Collection (and thus an Artist). The collection contains a single path per contour level; this path may be non-continuous in case there are multiple connected components.

@ahuang11 ahuang11 added the type: bug Something isn't correct or isn't working label Sep 21, 2023
@ahuang11 ahuang11 transferred this issue from holoviz/geoviews Sep 21, 2023
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants