【发布时间】:2022-01-07 03:12:51
【问题描述】:
我想绘制 imshow 热图,但最终图像看起来非常小且不成比例。 我的数据代表原子之间测量的距离(一个分子的 cca 10 个原子到另一个分子的 cca 30 个原子) - 结果是 array of arrays。我为说明准备了类似的输出,但是我的原始数据集更大:
import numpy as np
array1 = np.random.randint(20, size=30)
array2 = np.random.randint(20, size=30)
array3 = np.random.randint(20, size=30)
array4 = np.random.randint(20, size=30)
array5 = np.random.randint(20, size=30)
array6 = np.random.randint(20, size=30)
array7 = np.random.randint(20, size=30)
array8 = np.random.randint(20, size=30)
array9 = np.random.randint(20, size=30)
arrayOfArrays = np.array([array1, array2, array3, array4, array5, array6, array7, array8, array9])
然后我想制作热图来查看原子之间的距离,所以这是我的代码:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
im = ax.imshow(arrayOfArrays, origin='upper')
#this is here because I use this approach to define xticks and yticks in my original plot - here I modified the code with "len(range(0,30))" but in my original plot there is number of atoms for which I measured the distances (something like n_atoms=len(dataset1))
n_1=len(range(0,30))
n_2=len(range(0,9))
tick_interval = 1
ax.set_yticks(np.arange(n_2)[::tick_interval])
ax.set_xticks(np.arange(n_1)[::tick_interval])
# colorbar
cbar = fig.colorbar(im)
使用此特定绘图创建的最终图像看起来已经很小,但包含我的原始数据的图像更小,我根本看不到里面的颜色。
如果有任何建议,或者应该编辑代码的哪一部分,我真的很感激?我尝试编辑图片大小,添加“插值”,“ascpect”...
【问题讨论】:
-
你试过
ax.imshow(..., aspect='auto')吗?
标签: python arrays numpy matplotlib imshow