新的Seaborn对象(v0.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.,我如何将图例移动到子图中并自定义它的外观?
发布于 2022-09-07 11:06:45
从绘图界面中对图例位置的控制仍然是WIP,但是由于您使用的是外部matplotlib对象,所以传递其内容并不困难:
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
(
so.Plot(tips, x='total_bill', y='tip', color='day')
.add(so.Dot(pointsize=2))
.add(so.Line(color='k'), so.PolyFit(order=1), color=None)
.on(ax1)
.plot()
)
legend = f.legends.pop(0)
ax1.legend(legend.legendHandles, [t.get_text() for t in legend.texts])https://stackoverflow.com/questions/73633322
复制相似问题