Perhaps I donβt understand what exactly you are trying to do, since I donβt know what your data looks like, but it seems wrong that your contourf chart contourf the same axis as your bar3d chart. If you add an axis without 3D projection to a new shape, you can make the contourf graph just thin using hist . An example of using data from a random, normal distribution:
import numpy as np import matplotlib.pyplot as plt n_points = 1000 x = np.random.normal(0, 2, n_points) y = np.random.normal(0, 2, n_points) hist, xedges, yedges = np.histogram2d(x, y, bins=np.sqrt(n_points)) fig2D = plt.figure() ax2D = fig2D.add_subplot(111) ax2D.contourf(hist, interpolation='nearest', extent=(xedges[0], xedges[-1], yedges[0], yedges[-1])) plt.show()
returns an image of type this .
As for your second question regarding 3D color coding, how about this (using the same data as above but with 1/10 size):
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import matplotlib.colors as colors n_points = 100 x = np.random.normal(0, 2, n_points) y = np.random.normal(0, 2, n_points) hist, xedges, yedges = np.histogram2d(x, y, bins=np.sqrt(n_points))
I get this image .
source share