# Hvplot of an xarray dataset and add geopandas boundaries with geoview

**URL:** <https://discourse.holoviz.org/t/hvplot-of-an-xarray-dataset-and-add-geopandas-boundaries-with-geoview/7363>\
**Category:** hvPlot\
**Tags:** holoviews, hvplot\
**Created:** [June 25, 2024, 9:36pm UTC](https://discourse.holoviz.org/t/hvplot-of-an-xarray-dataset-and-add-geopandas-boundaries-with-geoview/7363 "2024-06-25T21:36:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MorningGlory747](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/morningglory747/32/6686_2.png) [@MorningGlory747](https://discourse.holoviz.org/u/MorningGlory747)\
**Post date:** [June 25, 2024, 9:36pm UTC](https://discourse.holoviz.org/t/hvplot-of-an-xarray-dataset-and-add-geopandas-boundaries-with-geoview/7363/1 "2024-06-25T21:36:17Z")

</div>

I’m currently following an online tutorial on how to perform an interactive visualization of an xarray dataset, but i’m also integrating geodataframe boundaries into the visualization with geoviews. While I am able to load the dataset and add the geopandas fields, I’m running into a few issues: I lose properties such as the Esri imagery and the grid no longer appears rotated. I attached an image at the end of the post that shows a print screen of the final plot.

I am using PyCharm Professional Edition 2023.3.2 with the Jupyter Notebook extension.

Can anybody tell me what’s going on? Cheers!

```auto
# read dataset
ds = xr.open_mfdataset(["\...\2021011506_000.nc"])

# Subset over all regions (need the geojson for this)
fields_geojson = gpd.GeoDataFrame.from_file("\...\rectangular_polygons.geojson")
fields_geojson = fields_geojson.set_crs('epsg:4326')

# Create subset based on the boundary limits of the fields
total_bounds = fields_geojson.geometry.total_bounds
min_lon, min_lat, max_lon, max_lat = total_bounds

# Create the crs based on the xarray dataset's metadata
rotp = ccrs.RotatedPole(
    pole_longitude=tmp_bbox.rotated_pole.grid_north_pole_longitude,
    pole_latitude=tmp_bbox.rotated_pole.grid_north_pole_latitude,
)

# Plotting the geodataframe with geoviews
gv_polygons = gv.Polygons(fields_geojson, vdims=['noChamp']).opts(
    alpha=1, line_color='black', projection=rotp, fill_color=None
)

# Create the map plot from the xarray dataset
map1 = ds.CaLDAS_A_SD_Avg.hvplot.quadmesh(
    x="rlon",
    y="rlat",
    cmap='Spectral_r',
    geo=True,
    crs=rotp,
    tiles='EsriImagery',
    frame_width=400,
    frame_height=600,
    dynamic=False,
    alpha=0.8
)

# combine dataset and geopandas
combined_plot = map1 * gv_polygons

```

```auto
print(ds)
<xarray.Dataset>
Dimensions: (rlat: 460, rlon: 522, time: 1)
Coordinates:
    lat (rlat, rlon) float32 dask.array<chunksize=(460, 522), meta=np.ndarray>
    lon (rlat, rlon) float32 dask.array<chunksize=(460, 522), meta=np.ndarray>
  * time (time) datetime64[ns] 2021-01-15T06:00:00
  * rlat (rlat) float32 -2.965 -2.943 -2.92 ... 7.318 7.34 7.363
  * rlon (rlon) float32 21.47 21.49 21.52 ... 33.15 33.17 33.19
Data variables:
    CaLDAS_P_I2_SFC (time, rlat, rlon) float32 dask.array<chunksize=(1, 460, 522), meta=np.ndarray>
    CaLDAS_P_DN_SFC (time, rlat, rlon) float32 dask.array<chunksize=(1, 460, 522), meta=np.ndarray>
    CaLDAS_A_SD_Veg (time, rlat, rlon) float32 dask.array<chunksize=(1, 460, 522), meta=np.ndarray>
    CaLDAS_A_SD_Avg (time, rlat, rlon) float32 dask.array<chunksize=(1, 460, 522), meta=np.ndarray>
    rotated_pole float32 ...
Attributes:
    product: CaLDAS
    Conventions: CF-1.6
    Remarks: Variable names are following the convention <Product>_<Type...
    License: These data are provided by the Canadian Surface Prediction ...

```

```auto
print(fields_geojson)
                                              geometry
0 POLYGON ((-75.23822 45.81036, -75.13822 45.810...
1 POLYGON ((-73.33674 46.69549, -73.23674 46.695...
2 POLYGON ((-73.55984 48.37041, -73.45984 48.370...
3 POLYGON ((-75.46064 46.19510, -75.36064 46.195...
4 POLYGON ((-75.64253 47.48844, -75.54252 47.488...

```

`pn.serve(combined_plot)`

 ![image](https://discourse.holoviz.org/uploads/default/original/2X/5/598bb5f9520d5847a6097fcd3b8d26b571825e11.jpeg)

---

<div class="post-metadata">

**Author:** ![ahuang11](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/ahuang11/32/4947_2.png) [@ahuang11](https://discourse.holoviz.org/u/ahuang11)\
**Post date:** [June 27, 2024, 2:51pm UTC](https://discourse.holoviz.org/t/hvplot-of-an-xarray-dataset-and-add-geopandas-boundaries-with-geoview/7363/2 "2024-06-27T14:51:42Z")

</div>

I believe you need to set `crs` and `projection`

See [Geographic Data — hvPlot 0.10.0rc2 documentation](https://hvplot.holoviz.org/user_guide/Geographic_Data.html#data-and-plot-projections)
