Polar plots#
We leverage the polar axes functionality in Matplotlib to construct polar plots.
A simple polar plot#
[1]:
import numpy as np
import scipp as sc
import plopp as pp
import matplotlib.pyplot as plt
# 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 = plt.Figure(figsize=(5, 5))
ax = fig.add_subplot(projection='polar')
# Make the plot and tweak the axes
p = pp.plot(da, ax=ax)
ax.set_xlim(0, 2*np.pi)
ax.grid(True)
p
[1]:
Plotting a sector#
Plotting data whose angular coordinate does not wrap around \(2\pi\) is also possible.
[2]:
# 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 = plt.Figure(figsize=(5, 5))
ax = fig.add_subplot(projection='polar')
ax.set_rorigin(0)
ax.grid(True)
pp.plot(da, ax=ax)
[2]:
Polar image plots#
It is also possible to plot 2d data on polar axes:
[3]:
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 = plt.Figure()
ax = fig.add_subplot(projection='polar')
pp.plot(da, ax=ax)
[3]:
Interactive polar plot#
It is also possible to use Plopp’s interactive visualizations with supplied axes:
[4]:
%matplotlib widget
plt.ioff() # Prevent the figure from showing up twice
[4]:
<contextlib.ExitStack at 0x7f7b245f7820>
[5]:
# 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 = plt.figure(figsize=(5, 5))
ax = fig.add_subplot(projection='polar')
ax.set_rorigin(0)
ax.grid(True)
# Use slicer plot
pp.slicer(da, ax=ax, autoscale='grow')
[5]: