我想使用 seaborn.tsplot
创建一个时间序列图喜欢在 this example from tsplot
documentation ,但随着图例移动到右侧,在图形之外。
基于 seaborn's timeseries.py 中的第 339-340 行,看起来像 seaborn.tsplot
目前不允许直接控制图例位置:
if legend:
ax.legend(loc=0, title=legend_name)
是否有 matplotlib 解决方法?
我正在使用 seaborn 0.6-dev。
最佳答案
确实,seaborn
到目前为止还不能很好地处理传说。您可以使用 plt.legend()
直接通过 matplotlib
控制图例属性,按照Matplotlib Legend Guide .
请注意,在 Seaborn 0.10.0 tsplot
中被删除,您可以使用 lineplot
复制(如果您愿意,可以使用不同的估计值)绘图而不是 tsplot
.
片段
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="darkgrid")
# Load the long-form example gammas dataset
gammas = sns.load_dataset("gammas")
# Plot the response with standard error
sns.lineplot(data=gammas, x="timepoint", y="BOLD signal", hue="ROI")
# Put the legend out of the figure
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
输出
关于python - 在seaborn tsplot中将图例移到图外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30490740/