Matplotlib 2D

2D plots can be made if you have a z value for each x and y value. This can just be a 2D array of z values. One can make a density plot from x and y values, by determining the number of points in a bin. For example we can start with a random set of x and y values.

N=100000
x=np.random.normal(size=N)
y=np.random.normal(size=N)
ax.hist2d(x,y) #makes a plot
ax.hexbin(x,y) #uses hexagon instead of square bins
hist,xed,yed=np.histogram2d(x,y,bins=25) #returns array
ax.imshow(hist,cmap='brg',extent=[xed[0],xed[-1],yed[0],yed[-1]])
cs=ax.contour(hist,[1,5,8],extent=[xed[0],xed[-1],yed[0],yed[-1]]))
ax.clabel(cs,inline=1,fontsize=10,fmt='%d')