【发布时间】:2019-02-25 16:23:48
【问题描述】:
我想将图例设置为水平显示。我不是指Matplotlib legend vertical rotation 中描述的图例的文本。我的 actual 案例包括用小部件指定的任意数量的系列。但下面的例子代表了挑战的要点:
片段:
# Imports
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# data
np.random.seed(123)
x = pd.Series(np.random.randn(100),index=pd.date_range('1/1/2000', periods=100)).cumsum()
y = pd.Series(np.random.randn(100),index=pd.date_range('1/1/2000', periods=100)).cumsum()
z = pd.Series(np.random.randn(100),index=pd.date_range('1/1/2000', periods=100)).cumsum()
df = pd.concat([x,y,z], axis = 1)
# plot
ax = plt.subplot()
for col in (df.columns):
plt.plot(df[col])
plt.legend(loc="lower left")
plt.xticks(rotation=90)
plt.show()
剧情:
默认布局似乎是垂直的。
查看 help(ax.legend) 和 docs 的详细信息,似乎没有直接的方法可以将其更改为水平。或者有吗?
编辑 - 所需图例:(使用 MS Paint)
【问题讨论】:
-
这是一个很好的链接来帮助你。 stackoverflow.com/questions/43521570/…
标签: python matplotlib