我正在尝试使用这些代码在 Python 中绘制 2D 直方图
from math import *
import pylab as p
import matplotlib.pyplot as plt
import numpy as np
x=part.points[:,0]
y=part.points[:,1]
z=part.points[:,2]
H, xedges, yedges = np.histogram2d(x, y, bins=(128,128))
H.shape, xedges.shape, yedges.shape
extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]
plt.imshow(H, extent=extent, interpolation='nearest')
plt.colorbar()
plt.xlabel("x")
plt.ylabel("y")
plt.show()
一切正常:我有一个代表每个单元格中的计数的颜色条。问题是我想要计数的日志,但函数 histogram2d 没有任何选项。
我想你可以简单地做
H_log = np.log(H)
…
plt.imshow(H_log,…)
(假设您没有空计数)。
如果您想要 3D 条形图,您可以调整example http://matplotlib.sourceforge.net/examples/mplot3d/hist3d_demo.htmlMatplotlib 文档中提供。
更一般地说,我衷心建议您检查非常有用的Matplotlib 画廊 http://matplotlib.sourceforge.net/gallery.html,当您正在寻找一些特定的绘图功能时。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)