Hello,
I have 2d array with fourier amplitudes that I would like to plot. I
found two options: contourf and imshow. This is my code:
omega = np.fft.rfftn(b_field, axes=(1, 0))
omega = np.abs(np.fft.fftshift(omega, axes=(1,)))
fig = plt.figure()
ax = fig.add_subplot(111)
M = omega.shape[0]
N = omega.shape[1]
ax.set_title('Spectrum')
ax.set_ylabel(r'Poloidal Mode Number m')
ax.set_xlabel(r'Toroidal Mode Number n')
ax.grid(True)
# Get rid of normalization
omega /= np.prod(omega.shape)
The problem with contourf is that I can't seem to stop it from
strongly interpolating the data, which obscures the discrete nature:
(see www.rath.org/contourf.png)
ctr = ax.contourf(np.arange(-N / 2, N / 2),
np.arange(0, M),
omega * 10000, 100, cmap=cm.YlOrRd, interpolation='nearest')
fig.colorbar(ctr)
ax.set_xlim(xmin= -(N - 1) / 2, xmax=(N - 1) / 2)
ax.set_ylim(ymin=0, ymax=M - 1)
fig.show()
Apparently contourf does not accept the interpolation='nearest' option.
Is there a way to make it stop interpolating?
The problem with imshow is, that it rescales the data so the
colorbar does not show the correct amplitudes (see
www.rath.org/imshow.png):
ctr = ax.imshow(omega, cmap=cm.YlOrRd, aspect='equal', interpolation='nearest',
origin='lower', extent=(-(N-1)/2, (N-1)/2, 0, M-1))
fig.colorbar(ctr)
ax.set_xlim(xmin= -(N - 1) / 2, xmax=(N - 1) / 2)
ax.set_ylim(ymin=0, ymax=M - 1)
fig.show()
Is there a way to get the proper amplitudes into the colorbar?
Thanks!
-Nikolaus
···
--
»Time flies like an arrow, fruit flies like a Banana.«
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C