0

What I want to do

Essentially I have the plot on the left (logarithmic scale), with the labels of the plot on the right (linear scale).

I just want to add an equally-spaced logarithmic y-axis (e.g. how the space between 4.2 and 8.7 is the same as the space between 18.3 and 38.3) to my plot, which was generated using logarithmic data but has a linear axis (since this is automatically created by matplotlib).

(Concrete examples of my case below.)

enter image description here

I want to plot this with an evenly-spaced logarithmic y-scale. In other words, I want to evenly space/display nonlinearly spaced frequencies for the y-axis labels.

Right now the y-scale is just linearly extrapolated and completely incorrect.

enter image description here

My code

# Wavelet parameters 
min_freq = 1 
max_freq = int(fs / 4)  
num_freqs = int(max_freq / 2)  

freq = np.logspace(np.log10(min_freq), np.log10(max_freq), num_freqs)

sec = 5
n_samples = sec*fs

brain_signal = samples[10*n_samples:11*n_samples]
cwtmatr = signal.cwt(brain_signal, signal.morlet2, freq, w=n)
cwtmatr = np.abs(cwtmatr)**2

t = np.linspace(0, sec, num=n_samples) 

plt.pcolormesh(t, freq, cwtmatr, cmap='Spectral', shading='gouraud')
plt.colorbar()

What I've tried

plt.pcolormesh(t, freq, cwtmatr, cmap='Spectral', shading='gouraud')
ax = plt.gca()
ax.yaxis.set_ticks(np.floor(freq[::40]))
plt.colorbar()

For obvious reasons, this leads to many low-valued y-ticks and sparse high-valued ticks

plt.pcolormesh(t, freq, cwtmatr, cmap='Spectral', shading='gouraud')
ax = plt.gca()
ax.set_yscale('log')
plt.colorbar()

Incorrect values and not evenly spaced.

enter image description here

  • I can't see anything that's obviously wrong with the plots. Please explain in more detail what is incorrect, and what result you'd like to get instead. – MB-F Mar 17 '22 at 11:13
  • I added another image at the top of the post to explain my situation and goals better, hope that helps! – neverreally Mar 17 '22 at 12:45
  • What do you mean by evenly spaced ? On your last plot, the power of 10 are evenly spaced, as expected for a log scale in base 10. – Liris Mar 17 '22 at 14:28
  • @neverreally Does [logarithmic scale, but require non-logarithmic labels](https://stackoverflow.com/questions/6431248/matplotlib-logarithmic-scale-but-require-non-logarithmic-labels) work for you? – MB-F Mar 17 '22 at 15:51
  • @MB-F, thanks for the comment -- unfortunately not, I've made more progress by specifying the labels themselves, but now I'm running into an issue with warped results and additional ticks that I'm not sure where they're coming from: https://imgur.com/a/iYpMCWJ – neverreally Mar 19 '22 at 07:33
  • @Liris you're right, sorry. Just the values are incorrect/don't correspond to my actual y-axis. – neverreally Mar 19 '22 at 07:36
  • Posted in more detail about the new issue here: https://dsp.stackexchange.com/questions/82045/why-does-using-a-log-scale-ruin-warp-my-scaleograms – neverreally Mar 19 '22 at 08:05

0 Answers0