@@ -33,7 +33,7 @@ class DataArrayPlotlyAccessor:
3333 ```
3434 """
3535
36- __all__ : ClassVar = ["line" , "bar" , "area" , "scatter" , "box" , "imshow" ]
36+ __all__ : ClassVar = ["line" , "bar" , "area" , "scatter" , "box" , "imshow" , "pie" ]
3737
3838 def __init__ (self , darray : DataArray ) -> None :
3939 self ._da = darray
@@ -274,6 +274,38 @@ def imshow(
274274 ** px_kwargs ,
275275 )
276276
277+ def pie (
278+ self ,
279+ * ,
280+ names : SlotValue = auto ,
281+ color : SlotValue = None ,
282+ facet_col : SlotValue = auto ,
283+ facet_row : SlotValue = auto ,
284+ ** px_kwargs : Any ,
285+ ) -> go .Figure :
286+ """Create an interactive pie chart.
287+
288+ Slot order: names -> facet_col -> facet_row
289+
290+ Args:
291+ names: Dimension for pie slice names/categories. Default: first dimension.
292+ color: Dimension for color grouping. Default: None (uses names).
293+ facet_col: Dimension for subplot columns. Default: second dimension.
294+ facet_row: Dimension for subplot rows. Default: third dimension.
295+ **px_kwargs: Additional arguments passed to `plotly.express.pie()`.
296+
297+ Returns:
298+ Interactive Plotly Figure.
299+ """
300+ return plotting .pie (
301+ self ._da ,
302+ names = names ,
303+ color = color ,
304+ facet_col = facet_col ,
305+ facet_row = facet_row ,
306+ ** px_kwargs ,
307+ )
308+
277309
278310class DatasetPlotlyAccessor :
279311 """Plotly Express plotting accessor for xarray Dataset.
@@ -307,7 +339,7 @@ class DatasetPlotlyAccessor:
307339 ```
308340 """
309341
310- __all__ : ClassVar = ["line" , "bar" , "area" , "scatter" , "box" ]
342+ __all__ : ClassVar = ["line" , "bar" , "area" , "scatter" , "box" , "pie" ]
311343
312344 def __init__ (self , dataset : Dataset ) -> None :
313345 self ._ds = dataset
@@ -519,3 +551,36 @@ def box(
519551 animation_frame = animation_frame ,
520552 ** px_kwargs ,
521553 )
554+
555+ def pie (
556+ self ,
557+ var : str | None = None ,
558+ * ,
559+ names : SlotValue = auto ,
560+ color : SlotValue = None ,
561+ facet_col : SlotValue = auto ,
562+ facet_row : SlotValue = auto ,
563+ ** px_kwargs : Any ,
564+ ) -> go .Figure :
565+ """Create an interactive pie chart.
566+
567+ Args:
568+ var: Variable to plot. If None, plots all variables with "variable" dimension.
569+ names: Dimension for pie slice names/categories.
570+ color: Dimension for color grouping.
571+ facet_col: Dimension for subplot columns.
572+ facet_row: Dimension for subplot rows.
573+ **px_kwargs: Additional arguments passed to `plotly.express.pie()`.
574+
575+ Returns:
576+ Interactive Plotly Figure.
577+ """
578+ da = self ._get_dataarray (var )
579+ return plotting .pie (
580+ da ,
581+ names = names ,
582+ color = color ,
583+ facet_col = facet_col ,
584+ facet_row = facet_row ,
585+ ** px_kwargs ,
586+ )
0 commit comments