新的 Seaborn 对象(v 0.12)非常好,但我很难处理图例自定义。特别是在使用 matplotlib 定义子图时。我的代码:
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(3.5, 3.5), gridspec_kw={'width_ratios':[1.5,1]}, dpi=dpi)
(
so.Plot(sert_neurons, x='mod_index_late', y='opto_mod_roc', color='sig_modulation')
.add(so.Dot(pointsize=2))
.add(so.Line(color='k'), so.PolyFit(order=1), color=None)
.limit(x=[-1, 1], y=[-1, 1])
.label(x='Spontaneous 5-HT modulation', y='Task evoked 5-TH modulation')
.on(ax1)
.plot()
)
plt.tight_layout()
sns.despine(trim=True)
图例似乎位于绘图范围之外。当我执行以下操作时:
ax1.legend(frameon=False, prop={'size': 5}, loc='upper left')
我会收到消息 No artists with labels found to put in legend.
如何将图例移动到子图内并自定义其外观?
matplotlib
句柄访问。 - some3128seaborn
的便利函数move_legend
来移动:sns.move_legend(ax2, "center right")
。 - Joshua Shew