简体   繁体   中英

Matplotlib density plot in polar coordinates?

I have an array saved as a txt file that has entries corresponding to the value of a distribution in polar coordinates. So it looks like this:

  f(r1,theta1) f(r1, theta2) ..... f(r1, theta_max)
  f(r2,theta1) f(r2, theta2) .....        .
        .                                 .
        .                                 .
        .                                 .
  f(r_max,theta1) .................f(r_max, theta_max)

I want to do a density plot of f (the higher f is, the more red I want the color to be). Is there a way to do this with matplotlib? Explicit code would be helpful, as I am majorly new to this.

In this example, a is you theta1...thetan, b is your r1...rn, c is your f(a, b):

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

#fake data:
a = np.linspace(0,2*np.pi,50)
b = np.linspace(0,1,50)
A, B = np.meshgrid(a, b)
c = np.random.random(A.shape)

#actual plotting
ax = plt.subplot(111, polar=True)
ax.set_yticklabels([])
ctf = ax.contourf(a, b, c, cmap=cm.jet)
plt.colorbar(ctf)

在此处输入图片说明

Essentially a filled contour plot in polar axis. You can specify alternative colormap with the cmap=... . cm.jet goes from blue to red, with red being the largest value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM