python画图如何调整图例位置_python – Matplotlib:如何水平显示图例元素?

我想指定是否垂直或水平显示图例.我并不是指

Matplotlib legend vertical rotation之后描述的图例文本.我的实际案例包括用小部件指定的任意数量的系列.但以下示例代表了挑战的要点:

片段:

# 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)

情节:

9HgTq.png

默认布局似乎是垂直的.

查看help(ax.legend)和docs的详细信息,似乎没有一种直接的方法将其更改为水平.还是有吗?

编辑 – 所需图例:(使用MS Paint)

IaDEC.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值