我也遇到过类似的问题,谷歌把我发到了这个帖子上。我的解决方案有点不同,不那么紧凑,但希望这对某人有用。
使用matplotlib.pyplot.imshow显示图像通常是显示二维数据的快速方法。但是,默认情况下,这会使用像素计数标记轴。如果要打印的二维数据对应于由数组x和y定义的某个统一网格,则可以使用matplotlib.pyplot.xticks和matplotlib.pyplot.yticks使用这些数组中的值标记x和y轴。这些标签将与轴上的像素计数相关联,对应于实际的网格数据。这样做比使用pcolor之类的工具要快得多。
以下是对您的数据的尝试:import matplotlib.pyplot as plt
# ... define 2D array hist as you did
plt.imshow(hist, cmap='Reds')
x = np.arange(80,122,2) # the grid to which your data corresponds
nx = x.shape[0]
no_labels = 7 # how many labels to see on axis x
step_x = int(nx / (no_labels - 1)) # step between consecutive labels
x_positions = np.arange(0,nx,step_x) # pixel count at label position
x_labels = x[::step_x] # labels you want to see
plt.xticks(x_positions, x_labels)
# in principle you can do the same for y, but it is not necessary in your case
本文介绍如何使用matplotlib.pyplot.imshow展示二维数据,并提供了一个实例,展示了如何通过定义网格和xticks/yticks来正确标记坐标轴,从而避免默认的像素计数标记。这种方法适用于快速且准确地呈现网格数据,比pcolor等工具更高效。
图形轴上的值&spm=1001.2101.3001.5002&articleId=116196464&d=1&t=3&u=6d86e592230746949e18112d7a47a61a)
4万+

被折叠的 条评论
为什么被折叠?



