Skip to content

Commit

Permalink
Always Rasterize with default UxDataArray.plot() (#762)
Browse files Browse the repository at this point in the history
* update default plotting method

* update value error

* update usage example

* Update accessor.py
  • Loading branch information
philipc2 authored Apr 15, 2024
1 parent 0020265 commit 54da444
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/examples/007-polygon-viz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
},
"source": [
"## Using the `UxDataArray.plot()` Accessor\n",
"For face-centered data, the default plotting method returns a Polygon plot."
"For face-centered data, the default plotting method returns a rasterized polygon plot."
]
},
{
Expand Down
31 changes: 9 additions & 22 deletions uxarray/plot/dataarray_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,25 @@
import holoviews as hv
from holoviews.operation.datashader import rasterize as hds_rasterize

from uxarray.plot.constants import N_FACE_THRESHOLD


import numpy as np


import uxarray.plot.utils


def plot(uxda, **kwargs):
"""Default Plotting Method for UxDataArray."""
"""Default plotting method for a ``UxDataArray``."""

if uxda._face_centered():
# default to polygon plot
if uxda.uxgrid.n_face < N_FACE_THRESHOLD:
# vector polygons for small datasets
if "exclude_antimeridian" in kwargs:
return polygons(uxda, **kwargs)
else:
return polygons(uxda, exclude_antimeridian=False, **kwargs)

else:
# rasterized polygons for larger datasets
return rasterize(uxda, method="polygon", **kwargs)
elif uxda._node_centered():
# default to point plots
return points(uxda, **kwargs)
elif uxda._edge_centered():
# default to edge plots
return points(uxda, **kwargs)
return rasterize(uxda, method="polygon", **kwargs)

elif uxda._edge_centered() or uxda._node_centered():
return rasterize(uxda, method="point", **kwargs)

else:
raise ValueError("Data must be either node or face centered.")
raise ValueError(
"Plotting variables on unstructured grids requires the data variable to be mapped to either the nodes, edges, or faces."
)


def datashade(
Expand Down

0 comments on commit 54da444

Please sign in to comment.