我是python初学者,我有一个问题无法解决。我需要用txt中的矩阵做一个2d的横截面图,也可以用xls。 矩阵示例:
4.52 4.54 4.52 4.44 4.34 4.28
5.10 4.92 4.82 4.80 4.66 4.44
6.12 5.80 5.57 5.50 5.15 4.70
6.47 6.54 6.27 6.13 6.21 5.97
8.11 8.73 8.70 8.63 8.84 8.55
我可以在代码中获得它:
a = np.loadtxt('matrix.txt')
然后我就要了。所以我有一部分代码,这使得一个hystogram像一个例子,但我不明白如何在这里集成我的矩阵:
import matplotlib.pyplot as plt
n = 100000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
xedges = np.linspace(-4, 4, 42)
yedges = np.linspace(-25, 25, 42)
hist, xedges, yedges = np.histogram2d(x, y, (xedges, yedges))
xidx = np.clip(np.digitize(x, xedges), 0, hist.shape[0]-1)
yidx = np.clip(np.digitize(y, yedges), 0, hist.shape[1]-1)
c = hist[xidx, yidx]
plt.scatter(x, y, c=c)
plt.show()
在这段代码的帮助下,我想用我的矩阵做一个hystogram,但我不明白怎么做。我会很感激的
显示矩阵的最简单方法是通过seaborn的热图。它看起来像:
由于这些值不是整数,也不是总和为1的浮点值,
a
似乎不是直方图另一种方法是创建3D plot:
相关问题 更多 >
编程相关推荐