Damao
Damao

Reputation: 35

How could I plot circular histogram like this in matplotlib?

I need plotting the circular histogram in matplotlib! They should look like this.

Upvotes: 1

Views: 220

Answers (1)

user14178341
user14178341

Reputation:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np; np.random.seed(1)

r = np.ones(100)*0.9
phi = np.random.rand(100)*2.*np.pi

hist, xedges, yedges = np.histogram2d(r, phi, bins=25, range=[[0, 1.2], [0,2*np.pi*26./25]])
R,Phi = np.meshgrid(xedges[:-1], yedges[:-1])
X = R*np.cos(Phi)
Y = -R*np.sin(Phi) 

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X[(R < 0.75) | (R > 1)] = np.nan
ax.plot_surface(X,Y, hist.T, alpha=0.2)
ax.plot_wireframe(X,Y, hist.T)
plt.show()

Output: enter image description here

Upvotes: 1

Related Questions