Skip to content

Help with weird uxarray, matplotlib, and orthographic plot #1489

Closed

Description

@erogluorhan

Today I was trying out different things with uxarray and some data and found an...oddity. With the bokeh backend, I get a nice pretty image with an Orthographic projection:

bokeh_ortho_plot

but when I try and use the matplotlib backend:

Screenshot 2026-04-13 at 10 56 38 AM

Does anyone know what I might be doing wrong? My "relevant" code is:

import uxarray as ux
import geoviews as gv
import geoviews.feature as gf
import cartopy
import cartopy.feature as cf
import cartopy.crs as ccrs
import holoviews as hv

graticules = cf.NaturalEarthFeature(
    category='physical',
    name='graticules_15',
    scale='50m')

ofeatures = gf.coastline(
    projection=ccrs.Orthographic(), line_width=1, scale="50m"
) * gf.borders(
    projection=ccrs.Orthographic(), line_width=1, scale="50m"
) * gv.Feature(graticules, group='Lines')

ortho_plot = uxds['SLP'][0].plot.polygons(
    rasterize=True, 
    cmap='viridis', 
    backend='matplotlib', 
    projection=ccrs.Orthographic(),
).opts(
    global_extent=True,
    xaxis=None,
    yaxis=None 
) * ofeatures

Just the backend change in ortho_plot is the differences between these two. Note: This is a mix of uxarray examples and Gemini/ChatGPT/whatever so I freely admit I probably did something stupid!

Originally posted by @mathomp4 in #1488

Activity

  1. moved this from 📚 Backlog to 📝 To-Do in UXarray Developmenton Apr 13, 2026
  2. mathomp4 commented on Apr 13, 2026

    @mathomp4

    @erogluorhan Here is a link to the file

    It's pretty small to make things easy.

  3. mathomp4 commented on Apr 13, 2026

    @mathomp4

    Whoops. I also forgot one sort of crucial thing in the Python snippet:

    file_path = r"c24.nc4"
    uxds = ux.open_dataset(file_path, file_path)

    I mean, you need to open the file 😄

  4. alioacar commented on May 15, 2026

    @alioacar
    Contributor

    The problem seems related to gv.Feature(graticules, group="Lines") using the Natural Earth graticules_15 feature. The base UXarray polygon plot, gf.coastline(), and gf.borders() all render correctly with the matplotlib backend but adding the graticules feature causes the rendering to collapse.

    field = uxds["SLP"][0].plot.polygons(
        rasterize=True,
        cmap="viridis",
        backend="matplotlib",
        projection=ccrs.Orthographic()
    ).opts(
        xaxis=None,
        yaxis=None,
    )
    field
    field * gf.coastline(scale="50m")
    field * gf.borders(scale="50m")
    field * gv.Feature(graticules, group="Lines")
    Image

    As a workaround, I was able to get the expected result by avoiding gv.Feature(graticules_15) and instead adding gridlines directly through the Cartopy axis using ax.gridlines(...) after rendering:

    renderer = hv.renderer("matplotlib")
    overlay = (
        field
        * gf.coastline(scale="50m")
        * gf.borders(scale="50m")
    )
    mpl_obj = renderer.get_plot(overlay)
    
    mpl_obj.handles["axis"].gridlines(
        draw_labels=False,
        linewidth=0.6
    )

    This suggests the issue may be somewhere in the GeoViews/Cartopy feature overlay or clipping pipeline rather than in UXarray itself. Hopefully this helps @mathomp4 :)

  5. erogluorhan commented on May 18, 2026

    @erogluorhan
    MemberAuthor

    @alioacar thanks a lot for looking into this and suggesting a workaround! I'll try to think about this case a bit more when I have some time.

  6. self-assigned this
    on Jun 29, 2026
  7. Sevans711 commented on Jun 29, 2026

    @Sevans711
    Collaborator

    Confirming, this looks like an upstream issue, I was able to reproduce it without using UXarray at all. See holoviz/geoviews#845 for more details!

  8. rajeeja commented on Jun 30, 2026

    @rajeeja
    Contributor

    Confirming, this looks like an upstream issue, I was able to reproduce it without using UXarray at all. See holoviz/geoviews#845 for more details!

    Thanks for pointing this out. It seems like our fix still holds

  9. erogluorhan commented on Jun 30, 2026

    @erogluorhan
    MemberAuthor

    Confirming, this looks like an upstream issue, I was able to reproduce it without using UXarray at all. See holoviz/geoviews#845 for more details!

    Thanks for pointing this out. It seems like our fix still holds

    So, are you suggesting that we should still put together a workaround, maybe something close to what @alioacar suggested? I think I lean more towards waiting for the fix on the holoviz/geoviews/issues/845.

  10. alioacar commented on Jul 1, 2026

    @alioacar
    Contributor

    I initially thought this was a more complex overlay issue. @erogluorhan I agree that it's better waiting for the fix to be merged

  11. rajeeja commented on Jul 1, 2026

    @rajeeja
    Contributor

    I misspoke — I was thinking of #1515 which fixed Bokeh Orthographic plots, but that's unrelated. The matplotlib+graticules issue is purely upstream in geoviews (holoviz/geoviews#845). Agree with you: wait for holoviz/geoviews#846 to merge.

  12. erogluorhan commented on Jul 1, 2026

    @erogluorhan
    MemberAuthor

    Okay, perfect, thanks for clarifying @rajeeja and @alioacar !

    Let's keep this open until the geoviews fix is released, and then we can give this a second try and hopefully close it once confirmed things work.

  13. moved this from 📝 To-Do to On Pause in UXarray Developmenton Jul 1, 2026
  14. added
    fix upstreamTo be fixed upstream, or awaiting a fix to be merged upstream; fixing it here is not the solution.
    on Jul 8, 2026
  15. erogluorhan commented on Sep 2, 2026

    @erogluorhan
    MemberAuthor

    Test it again once geoviews 1.15.2 is released and close if it looks good.

  16. mathomp4 commented on Sep 3, 2026

    @mathomp4

    Test it again once geoviews 1.15.2 is released and close if it looks good.

    Will do! Hopefully it is released soon :)

  17. moved this from On Pause to 🏗 In progress in UXarray Developmenton Oct 26, 2026
  18. moved this from 🏗 In progress to 👀 In review in UXarray Developmenton Oct 27, 2026
  19. moved this from 👀 In review to ✅ Done in UXarray Developmenton Oct 27, 2026
  20. erogluorhan commented on Oct 27, 2026

    @erogluorhan
    MemberAuthor

    @mathomp4 , geoviews 1.15.2 is now released and we closed this. Please feel free to reopen if you test it and think it is not resolved.

  21. mathomp4 commented on Nov 3, 2026

    @mathomp4

    @erogluorhan Sorry it took me so long, but I can see things are now good with geoviews 1.16.0. Thanks!

  22. erogluorhan commented on Nov 3, 2026

    @erogluorhan
    MemberAuthor

    29. @erogluorhan Sorry it took me so long, but I can see things are now good with geoviews 1.16.0. Thanks!

    No worries at all; thanks for confirming it works! Best,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

fix upstreamTo be fixed upstream, or awaiting a fix to be merged upstream; fixing it here is not the solution.visualizationPlotting or other visualizations

Type

No type

Fields

Priority

Low

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions