Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PolarColor map plot of grid data in Python

I want to plot a color map of a grid data, grid in polar form. In data, r ranges from 1 to 2 and theta 0 to 360. I want map like this:

enter image description here I plotted like this

#x1 of shape(12,)
#y1 0f shape(36,1)
#z of shape(36,12)
fig=plt.figure()  
ax=fig.add_subplot(111) #Output Figure 1
#ax=fig.add_subplot(111,polar='True') #Output Figure 2
ax=fig.add_subplot(111)
ax.pcolor(y1,x1,z)
plt.show()

Output: enter image description here

enter image description here

Any idea how to plot the above figure? I also tried converting r, theta into x,y then i got color map in r<1 range which i don't want.

like image 828
Ranjeet Avatar asked Sep 03 '26 19:09

Ranjeet


1 Answers

As pointed out here, pcolormesh() is useful for this.

import matplotlib.pyplot as plt
import numpy as np

theta = np.linspace(0, 2*np.pi, 36)
r = np.linspace(1, 2, 12)

R, THETA = np.meshgrid(r, theta)
Z = np.sin(THETA) * R

plt.subplot(111, projection='polar')
plt.pcolormesh(THETA, R, Z)
plt.gca().set_rmin(0.0)

plt.show()

output figure

like image 196
Alex Björling Avatar answered Sep 06 '26 10:09

Alex Björling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!