最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python如何繪制極坐標輪廓圖contourf

 更新時間:2023年08月16日 09:34:44   作者:小朱小朱絕不服輸  
這篇文章主要介紹了python如何繪制極坐標輪廓圖contourf問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

python繪制極坐標輪廓圖contourf

任務:將每個象限的風速,距離,角度繪制成極坐標輪廓圖。

使用極坐標畫等直線圖,可以用極地圖的 ax.contour ax.contourf 。

1.變量計算

每個象限的風速,距離就不再說怎么畫了,這里說下角度的計算。

兩個經(jīng)緯度之間的夾角(與正北方向的夾角):

# 點1到點2方向沿逆時針方向轉到正北方向的夾角
def LatLng2Degree(LatZero,LngZero,Lat,Lng):
    """
    Args:
        point p1(latA, lonA)
        point p2(latB, lonB)
    Returns:
        bearing between the two GPS points,
        default: the basis of heading direction is north
    """
    radLatA = math.radians(LatZero)
    radLonA = math.radians(LngZero)
    radLatB = math.radians(Lat)
    radLonB = math.radians(Lng)
    dLon = radLonB - radLonA
    y = math.sin(dLon) * math.cos(radLatB)
    x = math.cos(radLatA) * math.sin(radLatB) - math.sin(radLatA) * math.cos(radLatB) * math.cos(dLon)
    brng = math.degrees(math.atan2(y, x))
    brng = (brng + 360) % 360
    return brng

四個象限的距離,風速,角度一一對應。

2.極坐標繪制ax.contourf

import numpy as np
import matplotlib.pyplot as plt
#-- Generate Data -----------------------------------------
# Using linspace so that the endpoint of 360 is included...
azimuths = np.radians(np.linspace(0, 360, 20))
zeniths = np.arange(0, 70, 10)
r, theta = np.meshgrid(zeniths, azimuths)
values = np.random.random((azimuths.size, zeniths.size))
#-- Plot... ------------------------------------------------
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)
plt.show()

首先,創(chuàng)建極坐標軸,繪制輪廓圖。

fig, ax = subplots(subplot_kw=dict(projection='polar'))
cax = ax.contourf(theta, r, values, nlevels)

參數(shù)分別為theta:角度,r:半徑,values:輪廓的實際值,nlevels:要繪制的輪廓圖的層數(shù)。

這里theta, r, values 都需要是二維數(shù)組,需要通過列表轉化為列。

相當于需要先構造網(wǎng)格矩陣,對于坐標軸,一般使用

r, theta = np.meshgrid(zeniths, azimuths)

np.meshgrid函數(shù)去構造。

一般情況下,theta, r, values的對應關系是:

可以通過reshape將值轉化為二維數(shù)組

這里可以使用:

theta = np.radians(azimuths)
zeniths = np.array(zeniths)
values = np.array(values)
values = values.reshape(len(azimuths), len(zeniths))
r, theta = np.meshgrid(zeniths, np.radians(azimuths))

但當theta, r, values一一對應時,需要插值實現(xiàn)。

這里記得將角度轉化為弧度

r = np.array(r)
v = np.array(v)
angle = np.array(angle)
angle = np.radians(angle)
angle1, r1 = np.meshgrid(angle, r)  # r和angle構造網(wǎng)格矩陣
v_new = griddata((angle, r), v, (angle1, r1), method='linear')
cax = ax.contourf(angle1, r1, v_new, 20, cmap='jet')

這里python插值可以參考:python插值(scipy.interpolate模塊的griddata和Rbf)

可以解釋一下使用Rbf插值會報錯的原因,是因為有的方位角相同,比如多行是0度,這樣在使用Rbf插值的時候,要求矩陣可逆,則會出現(xiàn)報錯的情況。

插值完以后,這里還有一個點,就是把0度調整為正北方向。

ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)

運行結果:

可以看到四個象限的風速就用極坐標輪廓圖描述出來了。

總結

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論

通辽市| 宁陵县| 大足县| 宁明县| 长垣县| 河北区| 长汀县| 泸州市| 万全县| 永安市| 大竹县| 嘉义县| 泰顺县| 高清| 沂南县| 雷山县| 延庆县| 呼和浩特市| 台东市| 浮山县| 鹤岗市| 虎林市| 吉林市| 奈曼旗| 灵武市| 安西县| 噶尔县| 丰原市| 手游| 安龙县| 年辖:市辖区| 嘉祥县| 襄城县| 柘荣县| 新绛县| 紫云| 泾阳县| 天门市| 烟台市| 阿克陶县| 垦利县|