In [1]:
import psyplot.project as psy
import xarray as xr
%matplotlib inline
%config InlineBackend.close_figures = False
import numpy as np
First we create some sample data in the form of a 2D parabola
In [2]:
x = np.linspace(-1, 1.)
y = np.linspace(-1, 1.)
x2d, y2d = np.meshgrid(x, y)
z = - x2d**2 - y2d**2
ds = xr.Dataset(
{'z': xr.Variable(('x', 'y'), z)},
{'x': xr.Variable(('x', ), x), 'y': xr.Variable(('y', ), y)})
For a simple 2D plot of a scalar field, we can use the plot2d plot method:
In [3]:
p = psy.plot.plot2d(ds, cmap='Reds', name='z')
The plot
formatoption controls, how the plot is made. The default is a
pcolormesh
plot, but we can also make a
filled contour
plot. The levels of the contour plot are determined through the levels
formatoption.
In [4]:
p.update(plot='contourf', levels=5)
p.show()
The plot2d
method has several formatoptions controlling the color coding of your plot:
In [5]:
p.keys('colors')
The most important ones are
cbar
: To specify the location of the colorbarbounds
: To specify the boundaries for the color coding, i.e.
the categories which data range belongs to which colorcmap
: To specify the colormap
In [6]:
psy.close('all')