簡體   English   中英

如何在Matplotlib中反轉軸並設置極坐標圖的零位置?

[英]How do you reverse the axis and set the zero position for a polar plot in Matplotlib?

使用Matplotlib的極坐標圖時,theta軸的默認零位置為或,右角為逆時針方向增加,如本示例所示。

在此處輸入圖片說明

如何指定零位置並反轉theta的方向? 在撰寫本文時, 文檔相對有限。

軸方法set_theta_zero_locationset_theta_direction允許您分別指定零位置和增大theta的方向。 這是Matplotlib示例的修改版本。

import numpy as np
import matplotlib.pyplot as plt

r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r

ax = plt.subplot(111, projection='polar')
ax.plot(theta, r)
ax.set_rmax(2)
ax.set_rticks([0.5, 1, 1.5, 2])  # less radial ticks
ax.set_rlabel_position(-22.5)  # get radial labels away from plotted line
ax.grid(True)

# ---- mod here ---- #
ax.set_theta_zero_location("N")  # theta=0 at the top
ax.set_theta_direction(-1)  # theta increasing clockwise
# ---- mod here ---- #

ax.set_title("A line plot on a polar axis", va='bottom')
plt.show()

在此處輸入圖片說明

請注意,對於quiverplot,這些方法當前會產生奇怪的結果(請參閱GitHub問題)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM