如何在 matplotlib 中為極座標曲線新增彎曲文字?


以下是在 matplotlib 中為極座標曲線新增彎曲文字的方法:

步驟

  • 設定圖形尺寸並調整子圖之間的和周圍的填充。

  • 建立新圖形或啟用現有圖形。

  • “ax”新增到圖形中作為子圖排列的一部分。

  • 使用某些角度繪製線條,color='green'linewidth=2

  • 建立xy資料點,並使用plot()方法繪製一些曲線

  • 要顯示圖形,請使用show()方法。

示例

from matplotlib import pyplot as plt
from scipy.interpolate import interp1d
import numpy as np

plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

fig = plt.figure()
ax = fig.add_subplot(111, projection="polar")

for degree in [0, 90, 360]:
   rad = np.deg2rad(degree)
   ax.plot([rad, rad], [0, 1], color="green", linewidth=2)

for curve in [[[0, 90], [0.45, 0.75]]]:
   curve[0] = np.deg2rad(curve[0])
   x = np.linspace(curve[0][0], curve[0][1], 500)
   y = interp1d(curve[0], curve[1])(x)
   ax.plot(x, y, lw=7, color='red')

plt.show()

輸出

它將生成以下輸出:

更新於: 2021 年 10 月 19 日

655 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

立即開始
廣告
© . All rights reserved.