matplotlibのcontourf関数に問題があります。データをインポートする txt データ ファイルがあります。データの列 (pm1 と pm2) があり、2D ヒストグラムを実行しています。このデータを 3D ヒストグラムおよび等高線図としてプロットして、最大値がどこにあるかを確認したいと考えています。
これは私のコードです:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
rows = np.arange(200,1300,10)
hist, xedges, yedges = np.histogram2d (pm1_n, pm2_n, bins = (rows, rows) )
elements = (len(xedges) - 1) * (len(yedges) - 1)
xpos, ypos = np.meshgrid(xedges[:-1], yedges[:-1])
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros(elements)
dx = 0.1 * np.ones_like(zpos)
dy = dx.copy()
dz = hist.flatten()
#####The problem is here#####
#ax.contourf(xpos,ypos,hist)
#ax.bar3d(xpos, ypos, zpos, dx, dy, dz, zsort='average')
plt.show()
3D棒グラフをプロットできますが、等高線をプロットできませんhist
.contourf関数に配置するとエラーが発生します. Length of x must be number of columns in z
配置すると、xedgesとdz
yexgesInput z must be a 2D array
も使用しようとしましたが、これは解決しません.問題。
問題は関数 histogram2D の戻り値の形状に関係していると思います。しかし、私はそれを解決する方法がわかりません。
また、カラーコードが最小値から最大値に変化する 3D 棒グラフを実行したいと思います。とにかくこれを作ることはありますか?
ありがとうございました