我已经修改了这个示例:Matplotlib: Polar plot axis tick label location。我想在从极轴中心到 thetagrid 标签的 thetagrid 旁边的刻度标签(A、B、C、D 和 E)旁边添加刻度线。另外,我想要一个圆形结束每一行,直接在 thetagrid 标题(TG01、TG02 等)下方。您将在我的代码示例中看到这些刻度标签和 thetagrid 标题。从视觉上看,这是 TG01 行的一部分,用于演示我正在寻找的内容:
这是我当前的代码:
import numpy as np
import matplotlib.pyplot as plt
class Radar(object):
def __init__(self, fig, titles, label, rect=None):
if rect is None:
rect = [0.05, 0.15, 0.95, 0.75]
self.n = len(titles)
self.angles = [a if a <=360. else a - 360. for a in np.arange(90, 90+360, 360.0/self.n)]
self.axes = [fig.add_axes(rect, projection="polar", label="axes%d" % i)
for i in range(self.n)]
self.ax = self.axes[0]
# Show the labels
self.ax.set_thetagrids(self.angles, labels=titles, fontsize=14, weight="bold", color="black")
for ax in self.axes[1:]:
ax.patch.set_visible(False)
ax.grid(False)
ax.xaxis.set_visible(False)
self.ax.yaxis.grid(False)
for ax, angle in zip(self.axes, self.angles):
ax.set_rgrids(range(1, 6), labels=label, angle=angle, fontsize=12)
# hide outer spine (circle)
ax.spines["polar"].set_visible(False)
ax.set_ylim(0, 6)
ax.xaxis.grid(True, color='black', linestyle='-')
def plot(self, values, *args, **kw):
angle = np.deg2rad(np.r_[self.angles, self.angles[0]])
values = np.r_[values, values[0]]
self.ax.plot(angle, values, *args, **kw)
fig = plt.figure(1)
titles = ['TG01', 'TG02', 'TG03', 'TG04', 'TG05', 'TG06']
label = list("ABCDE")
radar = Radar(fig, titles, label)
radar.plot([3.75, 3.25, 3.0, 2.75, 4.25, 3.5], "-", linewidth=2, color="b", alpha=.7, label="Data01")
radar.plot([3.25, 2.25, 2.25, 2.25, 1.5, 1.75],"-", linewidth=2, color="r", alpha=.7, label="Data02")
radar.ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.10),
fancybox=True, shadow=True, ncol=4)
plt.show()
以及极坐标图目前的样子:
我仔细查看了使用 ax.xaxis.majorTicks 检索到的 ThetaTick 对象。但是,我在 ThetaTick 对象的属性中所做的任何更改都没有以我希望它们呈现的方式更改线条。