【发布时间】:2018-04-19 09:40:20
【问题描述】:
我正在尝试向 matplotlib 雷达/极坐标图添加图例。我对 matplotlib 很陌生,所以请原谅代码。我也希望这很简单,但我已经做了一个小时,却一无所获。
我有以下内容,它会在左下角生成一个标签列表,但是每当我尝试添加句柄以赋予代表标签的颜色时,我都会丢失图例。
# Set color of axes
plt.rc('axes', linewidth=0.5, edgecolor="#888888")
# Create polar plot
ax = plt.subplot(111, polar=True)
# Set clockwise rotation. That is:
ax.set_theta_offset(pi / 2)
ax.set_theta_direction(-1)
# Set position of y-labels
ax.set_rlabel_position(0)
# Set color and linestyle of grid
ax.xaxis.grid(True, color="#888888", linestyle='solid', linewidth=0.5)
ax.yaxis.grid(True, color="#888888", linestyle='solid', linewidth=0.5)
# Plot data
ax.plot(x_as, values, linewidth=0, linestyle='solid', zorder=3)
# Fill area
ax.fill(x_as, values, 'r', alpha=0.3)
plt.legend(labels=[self.get_object().name], loc=(-.42,-.13))
if not self.get_object().subscription is None:
if self.get_object().subscription.benchmark:
bx = plt.subplot(111, polar=True)
bx.plot(x_as, baseline, linewidth=0, linestyle='solid', zorder=3)
bx.fill(x_as, baseline, 'b', alpha=0.3)
plt.legend(labels=[self.get_object().name, 'Benchmark'], loc=(-.42,-.13))
我相信我需要
plt.lengend(handles=[some list], labels=[self.get_object().name, 'Benchmark'], loc=(-.42,-.13))
我不明白handles 的列表应该是什么,我尝试了很多东西,包括[ax, bx]、[ax.plt(), bx.plt()]、['r', 'b']
【问题讨论】:
标签: matplotlib