Data not mapping properly to Polygons when `rasterize=False` & Matplotlib Extension
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 124
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 1
Description
## Overview
I am attempting to visualize data that resides on unstructured grids. To achieve this, I am developing a `to_gdf` method that converts our unstructured grid representation into geometries (Polygons) that can be visualized.
I have been able to compute the geometries of the grid and collect them in a `spatialpandas.GeoDataFrame`, however when mapping data variables to the polygons, visualizing them with `rasterize=False` produces seemingly random results when compared to using `rasterize=True` when using the `matplotlib` backend.
Using the bokeh backend correctly maps the data with or without rasterization.
Here is the code for how we construct our geometries
```Python
def to_gdf(self, override=False, cache=True):
# return cached gdf
if self._gdf is not None and not override:
return self._gdf
# obtain polygon shells for shapely polygon construction
polygon_shells = self.polygon_shells
# list of shapely Polygons representing each Face in our grid
polygons = [Polygon(shell) for shell in polygon_shells]
# List of Polygons (non-split) and MultiPolygons (split across antimeridian)
corrected_polygons = [antimeridian.fix_polygon(P) for P in polygons]
# prepare geometry for GeoDataFrame
geometry = MultiPolygonArray(corrected_polygons)
# construct our GeoDataFrame with corrected polygons
gdf = GeoDataFrame({"geometry": geometry})
# cache instance of gdf
if cache:
self._gdf = gdf
return gdf
```
## Software Version Info
`uxarray` on branch "philipc2/wrapped-polygons" for development
`spatialpandas` 0.4.8
`shapely` 2.0.1
`geoviews` 1.9.6
`hvplot` 0.8.4
`holoviews` 1.16.2
`xarray` 2023.5.0
## MCVE
```Python
# on branch "philipc2/wrapped-polygons" for development
import uxarray as ux
import xarray as xr
import hvplot.pandas
import geoviews.feature as gf
hvplot.extension('matplotlib')
# load grid and data files
mpas_root_filepath = "../../test/meshfiles/mpas/other/"
mpas_dataset_filepath = mpas_root_filepath + "ocean.QU.480km.scrip.151209.nc"
data_path = mpas_root_filepath + "ocean.QU.480km.151209.nc"
uxgrid = ux.open_grid(mpas_dataset_filepath, use_dual=False)
# faces mapped to polygons with corrected antimeridian crossing, stored as a sp.GeoDataFrame
gdf = uxgrid.to_gdf()
# obtain a 1D slide of temperature that maps to each face
d_var = xrds['temperature'].values[0, :, 0]
gdf['d_var'] = d_var
# plot
gdf.hvplot.polygons(rasterize=False, geo=True, hover_cols='all', c="d_var", height=1000, width=2000, cmap='inferno') * gf.coastline
```
## Plots Showcasing Described Issue
## Sea Surface Temperature
### Raster Plot (MPL)
```Python
gdf.hvplot.polygons(rasterize=True, geo=True, hover_cols='all', c="d_var", height=1000, width=2000, cmap='inferno') * gf.coastline
```

### Non-Raster Plot (MPL)
```Python
gdf.hvplot.polygons(rasterize=False, geo=True, hover_cols='all', c="d_var", height=1000, width=2000, cmap='inferno') * gf.coastline
```

### Raster Plot (Bokeh)
### Non-Raster Plot (Bokeh)
## Ocean Depth
### Raster Plot

### Non-Raster Plot

Contributor guide
Assessment
This issue has not been assessed yet.