这是更多关于3D直方图创建Python中的一般问题。
This is more of a general question about 3d histogram creation in python.
我试图用X和Y阵列以下code创建一个3D柱状图
I have attempted to create a 3d histogram using the X and Y arrays in the following code
import matplotlib
import pylab
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
from matplotlib import cm
def threedhist():
X = [1, 3, 5, 8, 6, 7, 1, 2, 4, 5]
Y = [3, 4, 3, 6, 5, 3, 1, 2, 3, 8]
fig = pylab.figure()
ax = Axes3D(fig)
ax.hist([X, Y], bins=10, range=[[0, 10], [0, 10]])
plt.xlabel('X')
plt.ylabel('Y')
plt.zlabel('Frequency')
plt.title('Histogram')
plt.show()
不过,我收到以下错误
However, I am getting the following error
回溯(最近通话最后一个): 文件,1号线,在 a3dhistogram() 文件C:/用户/ ckiser /桌面/项目/汤姆/ Python文件/ threedhistogram.py,第24行,在a3dhistogram ax.hist([X,Y],箱柜= 10,范围= [[0,10],[0,10]]) 文件C: Python27 lib目录站点包 matplotlib axes.py,系7668,在HIST 米,箱柜= np.histogram(X [i]于,垃圾桶,权重=瓦特[Ⅰ],** hist_kwargs) 文件C: Python27 lib目录站点包 numpy的 lib目录 function_base.py,169线,直方图 MN,MX = [MI范围内+ 0.0英里] 类型错误:只能串联列表(不是浮动),列出
Traceback (most recent call last): File "", line 1, in a3dhistogram() File "C:/Users/ckiser/Desktop/Projects/Tom/Python Files/threedhistogram.py", line 24, in a3dhistogram ax.hist([X, Y], bins=10, range=[[0, 10], [0, 10]]) File "C:Python27libsite-packagesmatplotlibaxes.py", line 7668, in hist m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs) File "C:Python27libsite-packagesnumpylibfunction_base.py", line 169, in histogram mn, mx = [mi+0.0 for mi in range] TypeError: can only concatenate list (not "float") to list
我在该行尝试了code有和没有[ ax.hist([X,Y],箱柜= 10,范围= [[0,10],[0,10]]) 我也试过功能从numpy的无功而返 H,xedges,yedges = np.histogram2d(X,Y,箱柜=(10,10)) 我缺少的一个步骤或参数?任何意见将大大AP preciated。
I have tried the code with and without the "[" in the line ax.hist([X, Y], bins=10, range=[[0, 10], [0, 10]]) I have also tried the function from numpy without success H, xedges, yedges = np.histogram2d(x, y, bins = (10, 10)) Am I missing a step or a parameter? Any advice would be greatly appreciated.
推荐答案
在此应答有二维的解决方案散点和3D直方图。用法很简单:
In this answer there is a solution for 2D and 3D Histograms of scattered points. The usage is simple:
points, sub = hist2d_scatter( radius, density, bins=4 )
points, sub = hist3d_scatter( temperature, density, radius, bins=4 )
其中,子
是 matplotlib
插曲
实例(3D与否)和分
包含用于散点图的点。
Where sub
is a matplotlib
"Subplot"
instance (3D or not) and points
contains the points used for the scatter plot.
相关推荐
最新文章