如何为极坐标图 matplotlib 创建小刻度 [英] How to create minor ticks for polar plot matplotlib
本文介绍了如何为极坐标图 matplotlib 创建小刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于如下所示的 matplotlib 绘制的极坐标图,我对以下两件事感兴趣
I am interested in the following two things for the polar plot plotted by matplotlib shown below
- 如何为 r 轴上的极坐标图创建小刻度?
- 如何将r标签远离r刻度移动,如图所示,某些r刻度与轴接触.
推荐答案
极坐标图没有次要或主要的滴答声.因此,我认为您需要通过绘制小线段来手动创建小刻度线.
The polar plot does not have minor or major ticks. So I think you need to create the minor ticks manually by plotting small line segments.
例如:
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()
这篇关于如何为极坐标图 matplotlib 创建小刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文