使用 Python 绘制 2D 直方图
我正在尝试使用这些代码在 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 没有任何选项。
I'm trying to plot a 2D histogram in Python using these code
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()
Every thing works fine: I have a color bar which represent the counts in each cells. The thing is that I would like to have the log of the count but the function histrogram2d does not have any option for that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想你可以简单地这样做
(假设你没有空计数)。
如果您想要 3D 条形图,您可以采用 中提供的 示例 Matplotlib 文档。
更一般地说,当您正在寻找一些东西时,我衷心建议您查看非常有用的 Matplotlib gallery特定的绘图功能。
I guess that you could simply do
(assuming that you don't have null counts).
If you want a 3D bar chart instead, you can adapt the example provided in the Matplotlib documentation.
More generally, I heartily recommend that you check the very useful Matplotlib gallery, when you are looking for some specific graphing capabilities.