This is a more general question about creating 3D histograms in python.
I tried to create a three-dimensional histogram using 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 get the following error
Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> 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:\Python27\lib\site-packages\matplotlib\axes.py", line 7668, in hist m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs) File "C:\Python27\lib\site-packages\numpy\lib\function_base.py", line 169, in histogram mn, mx = [mi+0.0 for mi in range] TypeError: can only concatenate list (not "float") to list
I tried the code with and without "[" in the line ax.hist ([X, Y], bit = 10, range = [[0, 10], [0, 10]]) I also tried the function from numpy without success H , xedges, yedges = np.histogram2d (x, y, bins = (10, 10)) Am I missing a step or parameter? Any advice would be greatly appreciated.