简体   繁体   中英

How to polar plot contour a specific value from a 2D array?

How can I highlight a specific contour value in a polar plot?

azi is polar azimuth degrees (with 360 values).
dev is deviation degrees from horizontal (with 90 values).
W is a 2D array shaped (90,360) with values that range 0 to 110.

I need to highlight and contour the W-values that equal 90.
Below is the code I've tried:


a=np.radians(np.linspace(0,360,360).round()) # borehole azimuth - degrees converted to radians
d=np.radians(np.linspace(0,90,90).round())     # borehole deviation - degrees converted to radians
azi,dev=np.meshgrid(a,d)  # create numpy array 90x360 for borehole deviation
W=np.random.randint(80,100, size=(90,360))

ax2 = plt.subplot(111, projection= 'polar')  
ax2.set_theta_direction(-1)  
ax2.set_theta_zero_location("N")  
data=ax2.contourf(azi,dev, W)  
plt.contour(azi, dev, np.where(W == 90))  
plt.colorbar(data)  
plt.show()

However, I get the error:

TypeError: Input z must be at least a 2x2 array.  

I can't figure out how to contour and index the 2D- 'W' array values that equal 90.

Another solution might be to create a new 2D array of W==90 values and contour those values?

import numpy as np
import matplotlib.pyplot as plt

a=np.radians(np.linspace(0,360,360).round()) # borehole azimuth - degrees converted to radians
    d=np.radians(np.linspace(0,90,90).round())     # borehole deviation - degrees converted to radians
    azi,dip=np.meshgrid(a,d)  # create numpy array 90x360 for borehole deviation
    W=np.random.randint(80,100, size=(90,360))

# first we need to create a new 2D Numpy array (Z) from W where W=90
Z = np.zeros_like(W)
mask = np.isclose(W, 90)
Z[mask] = W[mask]

ax2 = plt.subplot(111, projection= 'polar')  
ax2.set_theta_direction(-1)  
ax2.set_theta_zero_location("N")  
data=ax2.contourf(azi,dip, W)  
plt.contour(azi, dip, Z)  # then plot contour using the new Z array
plt.colorbar(data)  
plt.show()

在此处输入图像描述

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