joyplot is a plot like this that was talked about on twitter a while ago.
This seems to be easy to plot in R's ggjoy package. There didn't seem to be anything similar in python.
By the way, the reason why it is called joy plot is that the cover of the album "Unknown Pleasures" of the band Joy Division looks like the one below, so it seems to be called joy plot.
So, when using this joyplot, it seems polite to plot while listening to this. (Is a lie)
Looking at this plot, I thought that it would be useful for Bayesian update and spectrogram plotting, so this time I will try spectrogram plotting for the time being. Use the example of the scipy spectrogram as it is.
from scipy import signal
import matplotlib.pyplot as plt
fs = 10e3
N = 1e5
amp = 2 * np.sqrt(2)
noise_power = 0.01 * fs / 2
time = np.arange(N) / float(fs)
mod = 500*np.cos(2*np.pi*0.25*time)
carrier = amp * np.sin(2*np.pi*3e3*time + mod)
noise = np.random.normal(scale=np.sqrt(noise_power), size=time.shape)
noise *= np.exp(-time/5)
data = carrier + noise
f, t, Sxx = signal.spectrogram(data, fs, nperseg=1000, noverlap=900)
I refer to here on stackoverflow.
y = Sxx.T
#Since there are many, slice it.
y_subset_num = 10
x_subset_num = 20
y = y[0:y_subset_num, 0:x_subset_num]
ny, nx = y.shape
x = f[0:x_subset_num]
y_delta = (y.max() - y.min()) / ny #This y=Plot by shifting by delta.
yticks = [] #For saving the position of yticks
fig = plt.figure()
ax = fig.add_subplot(111)
for iy in np.arange(ny):
offset = (ny-iy) * y_delta #Plot from top to bottom
y_value = y[iy] + offset #Shift by offset.
ax.plot(x, y_value, color='w', lw=1, zorder=iy)
ax.fill_between(x=x, y1=y_value, y2=offset, alpha=0.5, lw=0, zorder=iy, color="red")
# y_Plot the value line and paint under it.
yticks.append(offset)
#The top of the plot is younger, so reverse the order.
yticks = yticks[::-1]
ytickslabel = np.arange(len(yticks))[::-1]
ax.set_yticks(yticks)
ax.set_yticklabels(ytickslabel)
ax.set_xlabel("Frequency [Hz]")
plt.show()
I feel like this. In order to make it look beautiful, you need to make some adjustments. You need to change around `` `y_delta``` in the above code.
I discovered that joyplot was added to the seaborn example last month. https://github.com/mwaskom/seaborn/blob/master/examples/kde_joyplot.py
We also found joypy.
It would be better to use either of these two.
Recommended Posts