circular heatmap python

Solutions on MaxInterview for circular heatmap python by the best coders in the world

showing results for - "circular heatmap python"
Emilio
17 May 2016
1from pylab import *
2import numpy as np
3from scipy.interpolate import griddata
4
5#create 5000 Random points distributed within the circle radius 100
6max_r = 100
7max_theta = 2.0 * np.pi
8number_points = 5000
9points = np.random.rand(number_points,2)*[max_r,max_theta]
10
11#Some function to generate values for these points, 
12#this could be values = np.random.rand(number_points)
13values = points[:,0] * np.sin(points[:,1])* np.cos(points[:,1])
14
15#now we create a grid of values, interpolated from our random sample above
16theta = np.linspace(0.0, max_theta, 100)
17r = np.linspace(0, max_r, 200)
18grid_r, grid_theta = np.meshgrid(r, theta)
19data = griddata(points, values, (grid_r, grid_theta), method='cubic',fill_value=0)
20
21#Create a polar projection
22ax1 = plt.subplot(projection="polar")
23ax1.pcolormesh(theta,r,data.T)
24plt.show()
25