我正在制作一個楔形圖(在空間中繪制類星體,RA 為 theta,Dec 為 r)。我需要在 0 的兩側設定極坐標圖的限制。我的限制應該從 45 度到 315 度,這兩個值之間為 0 度(45-0-315)。我該怎么做呢?
這是我的代碼:
import numpy as np
import matplotlib.pyplot as plt
theta = (np.pi/180)*np.array([340.555906,3.592373,32.473440,33.171584,35.463857,44.268397,339.362504,345.211906,346.485567,346.811945,348.672405,349.180736,349.370850,353.098343])
r = np.array([-32.906663,-33.842402,-32.425917,-32.677975, -30.701083,-31.460307,-32.909861,-30.802969,-33.683759,-32.207783,-33.068686,-33.820102,-31.438195,-31.920375])
colors = 'red'
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
c = ax.scatter(theta, r, c=colors, cmap='hsv', alpha=0.75)
plt.show()
如果我設定限制:
ax.set_thetamin(45)
ax.set_thetamax(-45)
我得到了圖表的正確切片,但 theta 軸上的值錯誤(軸現在從 -45-45 度開始)。
如果我設定限制:
ax.set_thetamin(45)
ax.set_thetamax(315)
我得到了圖表的錯誤部分,但 theta 軸上的值正確。
該怎么辦?
uj5u.com熱心網友回復:
thetamin如果您對and有正負值,matplotlib 似乎只會使 theta 限制跨越 theta=0 thetamax。從檔案字串中
為了完整起見,我將所有內容放在您的腳本中:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
theta = (np.pi/180)*np.array([340.555906,3.592373,32.473440,33.171584,35.463857,44.268397,339.362504,345.211906,346.485567,346.811945,348.672405,349.180736,349.370850,353.098343])
r = np.array([-32.906663,-33.842402,-32.425917,-32.677975, -30.701083,-31.460307,-32.909861,-30.802969,-33.683759,-32.207783,-33.068686,-33.820102,-31.438195,-31.920375])
colors = 'red'
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
c = ax.scatter(theta, r, c=colors, cmap='hsv', alpha=0.75)
ax.set_thetamin(45)
ax.set_thetamax(-45)
fmt = lambda x, pos: "{:g}".format(np.degrees(x if x >= 0 else x 2 * np.pi))
ax.xaxis.set_major_formatter(ticker.FuncFormatter(fmt))
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/440745.html
標籤:Python 麻木的 matplotlib 天文学
上一篇:不同大小的Python圖
