繁体   English   中英

使用Python的2D直方图

[英]2D histogram with Python

我正在尝试使用这些代码在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()

一切都运行正常:我有一个颜色条,代表每个单元格中的计数。 问题是我想得到计数的日志,但函数histrogram2d没有任何选项。

我想你可以做到

H_log = np.log(H)
…
plt.imshow(H_log,…)

(假设您没有空计数)。

如果您想要3D条形图,则可以调整Matplotlib文档中提供的示例

更一般地说,当您正在寻找一些特定的图形功能时,我衷心建议您检查非常有用的Matplotlib库

在这个答案中,有一个2D和3D散点图和气泡直方图的解决方案。

points, sub = hist2d_scatter( radius, density, bins=4 )

points, sub = hist3d_scatter( temperature, density, radius, bins=4 )

其中submatplotlib "Subplot"实例(3D或不是3D),并且points包含用于散点图的点。 在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM