2D直方图与Python [英] 2D histogram with Python
问题描述
我想用这些code绘制Python中的2D直方图
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()
每一件事情正常工作:我有重新present计数在每一个细胞中的彩条。问题是,我想有计数,但功能histrogram2d的日志不具有任何选项。
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.
推荐答案
我想,你可以简单地做
H_log = np.log(H)
…
plt.imshow(H_log,…)
(假设你没有空计数)。
(assuming that you don't have null counts).
如果你想有一个三维条形图,而不是,您可以调整例如在Matplotlib文档中提供。
If you want a 3D bar chart instead, you can adapt the example provided in the Matplotlib documentation.
更一般地,我衷心建议您检查非常有用的 Matplotlib库,当你寻找一些具体的图形功能。
More generally, I heartily recommend that you check the very useful Matplotlib gallery, when you are looking for some specific graphing capabilities.
这篇关于2D直方图与Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!