问题描述
我试图根据时间段绘制 y 尺度的频谱图,所以我想要一个反向的对数尺度.
问题是:我找到了使用 pcolormesh()
而不是使用 imshow()
的方法. imshow()
似乎比 pcolormesh()
更有效率,也就是说,对我来说,有理由更喜欢它!
我错过了什么吗?
我不知道如何说得更清楚,所以这里有一个可重现的例子:
将matplotlib.pyplot导入为plt将numpy导入为np大小 = 10数据 = np.arange(size * size).reshape((size, size))x_start = 1x_end = 10y_start = 1y_end = 10范围 = [x_start, x_end, y_start, y_end]图,轴 = plt.subplots(1,4)轴 [0].set_yscale('log')im =axis[0].imshow(data,extent=extent,origin='upper',interpolation='None',cmap='viridis')轴 [1].set_yscale('log')im2 =轴[1] .imshow(数据,范围=范围,原点=下限",插值=无",cmap ="viridis")axes [2] .set_yscale('log')im2 = 轴 [2].imshow(数据,范围=范围,原点='下',插值='无',cmap='viridis')轴[2].invert_yaxis()y = np.arange(1,11)*0.1x = np.arange(0,10)axes [3] .set_yscale('log')im3 =轴[3] .pcolormesh(x,1/y,数据)axes [0] .set_title(不正确")axes [1] .set_title(不正常")axes [2] .set_title(不正常")轴[3].set_title("OK")plt.tight_layout()plt.show()
您在上一张图像中看到,使用 imshow()
不会改变紧坐标,即使我使用 lower
或upper
origin
.通过 pcolormesh()
,我实现了在图的底部获得紧密的坐标.
我希望通过使用 imshow()
获得ok"的数字!
这个问题是相对于这个问题的:
I'm trying to plot spectrogram with y-scale depending on the period, so I want to have a reversed log-scale.
The thing is: I found how to do it using pcolormesh()
, not by using imshow()
. imshow()
seems to be more efficient than pcolormesh()
, that is, for me, a great reason to prefer it !
Did I miss something ?
I do not know how to say more clearly so here is a reproducible example:
import matplotlib.pyplot as plt
import numpy as np
size = 10
data = np.arange(size * size).reshape((size, size))
x_start = 1
x_end = 10
y_start = 1
y_end = 10
extent = [x_start, x_end, y_start, y_end]
fig, axes = plt.subplots(1,4)
axes[0].set_yscale('log')
im = axes[0].imshow(data, extent=extent, origin='upper', interpolation='None', cmap='viridis')
axes[1].set_yscale('log')
im2 = axes[1].imshow(data, extent=extent, origin='lower', interpolation='None', cmap='viridis')
axes[2].set_yscale('log')
im2 = axes[2].imshow(data, extent=extent, origin='lower', interpolation='None', cmap='viridis')
axes[2].invert_yaxis()
y = np.arange(1,11)*0.1
x = np.arange(0,10)
axes[3].set_yscale('log')
im3 = axes[3].pcolormesh(x, 1/y , data)
axes[0].set_title("not ok")
axes[1].set_title("not ok")
axes[2].set_title("not ok")
axes[3].set_title("OK")
plt.tight_layout()
plt.show()
You see on the previous image that tight ordinates do not change using imshow()
, they are always on the top of the figure even if I use lower
or upper
origin
. With pcolormesh()
, I achieved to get tight ordinates on the bottom of the graph.
I would dream to get the "ok" figure by using imshow()
!
This question is relative to this one: Aggregate several AxesSubplot after multiprocessing to draw a matplotlib figure
Is this what you are trying to get?
axes[1].set_yscale('log')
im2 = axes[1].imshow(data, extent=extent, origin='lower', interpolation='None', cmap='viridis')
axes[1].invert_yaxis()
这篇关于更改 y 对数比例 imshow()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!