@@ -349,3 +349,49 @@ canvas.show()
349349
350350 (<Figure size 590.551x324.803 with 1 Axes>,
351351 array([[<Axes: xlabel='x'>]], dtype=object))
352+
353+ ### xarray data
354+
355+ Plot labelled [ xarray] ( https://docs.xarray.dev ) data directly
356+ (` pip install maxplotlibx[xarray] ` ). Axes come from the coordinates,
357+ labels from the ` long_name ` and ` units ` attributes, and titles from the
358+ coordinates you selected. ` import maxplotlib.xarray ` adds a ` .maxplot `
359+ accessor that mirrors xarray’s own ` .plot ` API and returns an ordinary
360+ ` Canvas ` , so the backend is still chosen when rendering:
361+
362+ ``` python
363+ import xarray as xr
364+
365+ import maxplotlib.xarray # registers da.maxplot and ds.maxplot
366+
367+ t = np.linspace(0 , 1.5 , 6 )
368+ xs = np.linspace(0 , 2 * np.pi, 80 )
369+ ys = np.linspace(- 1 , 1 , 50 )
370+ wave = xr.DataArray(
371+ np.sin(xs - 2 * t[:, None , None ]) * np.exp(- 3 * ys[None , :, None ] ** 2 ),
372+ dims = (" t" , " y" , " x" ),
373+ coords = {" t" : (" t" , t, {" units" : " s" }), " y" : ys, " x" : (" x" , xs, {" units" : " m" })},
374+ name = " phi" ,
375+ attrs = {" long_name" : " Potential" , " units" : " V" },
376+ )
377+
378+ wave.maxplot.pcolormesh(col = " t" , col_wrap = 3 , canvas_kwargs = {" width" : " 16cm" , " ratio" : 0.6 }).show()
379+ ```
380+
381+ ![ ] ( README_files/figure-commonmark/cell-20-output-1.png )
382+
383+ (<Figure size 944.882x566.929 with 7 Axes>,
384+ array([[<Axes: title={'center': 't = 0 s'}, ylabel='y'>,
385+ <Axes: title={'center': 't = 0.3 s'}>,
386+ <Axes: title={'center': 't = 0.6 s'}>],
387+ [<Axes: title={'center': 't = 0.9 s'}, xlabel='x [m]', ylabel='y'>,
388+ <Axes: title={'center': 't = 1.2 s'}, xlabel='x [m]'>,
389+ <Axes: title={'center': 't = 1.5 s'}, xlabel='x [m]'>]],
390+ dtype=object))
391+
392+ The same works through Canvas methods,
393+ e.g. ` canvas.plot(da, hue="species") ` ,
394+ ` ax.pcolormesh(da, xcoord="R", ycoord="Z") ` for curvilinear grids, or
395+ ` Canvas.facet(da, col="t") ` . ` ds.maxplot.scatter(x=..., y=..., hue=...) `
396+ plots one Dataset variable against another. See the [ xarray
397+ tutorial] ( tutorials/tutorial_17_xarray.ipynb ) for more.
0 commit comments