[英]How to polar plot contour a specific value from a 2D array?
How can I highlight a specific contour value in a polar plot?如何突出显示极坐标 plot 中的特定轮廓值?
azi is polar azimuth degrees (with 360 values). azi 是极地方位角度数(具有 360 个值)。
dev is deviation degrees from horizontal (with 90 values). dev 是与水平方向的偏差度(有 90 个值)。
W is a 2D array shaped (90,360) with values that range 0 to 110. W 是一个形状为 (90,360) 的二维数组,其值范围为 0 到 110。
I need to highlight and contour the W-values that equal 90.我需要突出显示等于 90 的 W 值。
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.我不知道如何对等于 90 的 2D-“W”数组值进行轮廓和索引。
Another solution might be to create a new 2D array of W==90 values and contour those values?另一种解决方案可能是创建一个新的 W==90 值的二维数组并对这些值进行轮廓化?
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.