如何为极坐标图 matplotlib 创建小刻度

Tia*_*ian 8 python matplotlib

我对下面显示的 matplotlib 绘制的极坐标图的以下两件事感兴趣

  1. 如何在 r 轴上为极坐标图创建小刻度?
  2. 如何将 r 标签移离 r 刻度线,如图所示,一些 r 刻度线与轴接触。

在此处输入图片说明

Imp*_*est 5

极坐标图没有次要或主要刻度。所以我认为你需要通过绘制小线段来手动创建小刻度。

例如:

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.margins(y=0)
ax.set_rticks([0.5, 1, 1.5, 2])  # less radial ticks
ax.set_rlabel_position(120)  # get radial labels away from plotted line

ax.grid(True)

tick = [ax.get_rmax(),ax.get_rmax()*0.97]
for t  in np.deg2rad(np.arange(0,360,5)):
    ax.plot([t,t], tick, lw=0.72, color="k")

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

在此处输入图片说明