如何在极轴的周边线上添加刻度线?

时间:2017-06-01 21:48:16

标签: python matplotlib

我正在尝试使用matplotlib绘制极坐标图。如何在周边线上添加勾选的刻度标记?

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(30, 30))
ax = plt.subplot(111, polar=True)
ax.set_rmax(1)
plt.show()

grades, have no ticks

应该有这样的标记(关闭彩色数据): polar plot

我尝试过set_xtickstickslabelthethagrid。但我找不到解决方案。

请帮忙。

1 个答案:

答案 0 :(得分:1)

似乎在matplotlib中没有实现径向刻度标记(仅限刻度标签)。如果你不介意,你可能想要考虑自己创建它们。例如:

import numpy as np
import matplotlib.pyplot as plt

ax = plt.subplot(111, polar=True)
ax.xaxis.get_gridlines()[2].set_linestyle('-')

# Make ticks
tick_length = 0.5
start_theta = np.pi * 0.5
for i in range(0, 42, 2):
    end_r = np.sqrt(i ** 2 + tick_length ** 2)
    if i == 0:
        end_theta = 0
    else:
        end_theta = start_theta - np.arctan(tick_length / i)
    ax.plot([start_theta, end_theta], [i, end_r], color='k')

ax.set_rmax(40)
ax.set_rticks(range(0, 41, 10))
ax.set_rlabel_position(90)
for t in ax.yaxis.get_major_ticks():
    t.label1.set_va('center')
    t.label1.set_ha('right')

plt.show()

enter image description here