相关疑难解决方法(0)

更改matplotlib imshow()图轴上的值

说我有一些输入数据:

data = np.random.normal(loc=100,scale=10,size=(500,1,32))
hist = np.ones((32,20)) # initialise hist
for z in range(32):
    hist[z],edges = np.histogram(data[:,0,z],bins=np.arange(80,122,2))
Run Code Online (Sandbox Code Playgroud)

我可以用它绘图imshow():

plt.imshow(hist,cmap='Reds')
Run Code Online (Sandbox Code Playgroud)

得到:

在此输入图像描述

但是,x轴值与输入数据不匹配(即平均值为100,范围为80到122).因此,我想更改x轴以显示值edges.

我试过了:

ax = plt.gca()
ax.set_xlabel([80,122]) # range of values in edges
...
# this shifts the plot so that nothing is visible
Run Code Online (Sandbox Code Playgroud)

ax.set_xticklabels(edges)
...
# this labels the axis but does not centre around the mean:
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

关于如何更改轴值以反映我正在使用的输入数据的任何想法?

python numpy matplotlib

69
推荐指数
2
解决办法
11万
查看次数

标签 统计

matplotlib ×1

numpy ×1

python ×1