Polar plots#
We leverage the polar axes functionality in Matplotlib to construct polar plots.
A simple polar plot#
[1]:
%matplotlib inline
import numpy as np
import scipp as sc
import plopp as pp
import matplotlib.pyplot as plt
plt.ioff()
[1]:
<contextlib.ExitStack at 0x7f2e500f7010>
[2]:
# Make some spiral data
N = 150
r = sc.linspace('theta', 0, 10, N, unit='m')
theta = sc.linspace('theta', 0, 12, N, unit='rad')
da = sc.DataArray(data=r, coords={'theta': theta})
# Construct figure axes with Matplotlib
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
# Make the plot and tweak the axes
polar1d = pp.plot(da, ax=ax, grid=True)
polar1d
[2]:
Plotting a sector#
Plotting data whose angular coordinate does not wrap around \(2\pi\) is also possible.
[3]:
# Make data
N = 50
r = np.random.normal(loc=50, scale=5, size=N)
theta = np.radians(np.linspace(180, 200, N))
da = sc.DataArray(
data=sc.array(dims=['theta'], values=r, unit='m'),
coords={'theta': sc.array(dims=['theta'], values=theta, unit='rad')},
)
# Make axes and plot
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax.set_rorigin(0)
pp.plot(da, ax=ax, grid=True)
[3]:
Polar image plots#
It is also possible to plot 2d data on polar axes:
[4]:
da = pp.data.data2d(binedges=True, unit='K')
da.coords['x'] = sc.linspace('x', 0, 2 * np.pi, da.sizes['x'] + 1, unit='rad')
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
pp.plot(da, ax=ax)
[4]:
Interactive polar plot#
It is also possible to use Plopp’s interactive visualizations with supplied axes:
[5]:
%matplotlib widget
plt.ioff() # Prevent the figure from showing up twice
[5]:
<contextlib.ExitStack at 0x7f2e241828c0>
[6]:
# Make data
N = 50
r = np.random.normal(loc=50, scale=5, size=(N, N))
theta = np.radians(np.linspace(180, 200, N))
phi = np.radians(np.linspace(0, 90, N))
da = sc.DataArray(
data=sc.array(dims=['phi', 'theta'], values=r, unit='m'),
coords={
'theta': sc.array(dims=['theta'], values=theta, unit='rad'),
'phi': sc.array(dims=['phi'], values=phi, unit='rad'),
},
)
# Make axes
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax.set_rorigin(0)
# Use slicer plot
pp.slicer(da, ax=ax, grid=True, autoscale=False)
[6]: