更改y日志比例imshow()

2024-03-29 10:54:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用y标度绘制谱图,这取决于周期,所以我想要一个反向的对数标度。在

问题是:我发现了如何使用pcolormesh(),而不是使用imshow()imshow()似乎比pcolormesh()更有效率,这是我喜欢它的一个很好的理由!在

我错过什么了吗?在

我不知道怎么说得更清楚,所以这里有一个可复制的例子:

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()

enter image description here

在前面的图片中,使用imshow()不会改变紧密坐标,即使我使用lowerupperorigin,它们也始终位于图的顶部。使用pcolormesh(),我实现了在图的底部获得紧密的坐标。在

我梦想通过使用imshow()得到“确定”的数字!在

这个问题与这个问题有关:Aggregate several AxesSubplot after multiprocessing to draw a matplotlib figure


Tags: logdatasizetitlenppltstartextent
1条回答
网友
1楼 · 发布于 2024-03-29 10:54:58

这就是你想要的吗?在

axes[1].set_yscale('log')
im2 = axes[1].imshow(data, extent=extent, origin='lower', interpolation='None', cmap='viridis')
axes[1].invert_yaxis()

enter image description here

相关问题 更多 >