2D Bar Graph with Python

I am trying to build a 2D histogram in Python using this 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() 

Everything works great: I have a color bar that represents the counts in each cell. The fact is that I would like to have a counter log, but the histrogram2d function has no option for this.

+3
source share
2 answers

I guess you could just do

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

(provided that you do not have a null value).

If you want to use a three-dimensional chart, you can adapt example in the Matplotlib documentation.

In general, I wholeheartedly recommend that you check out the very useful Matplotlib gallery when you are looking for some graphical display capabilities.

+5
source

In this answer there is a solution for two-dimensional and three-dimensional scattered and histograms of bubbles.

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

Where sub is the matplotlib "Subplot" matplotlib "Subplot" (3D or not), and points contains the points used for the scatter plot. enter image description here

+3
source

All Articles