python中定义图片位置示意图_用户在python中定义的图例

使用fill_bettween绘制数据将自动包含图例中的填充区域.

要包括两个数据集重叠的区域,可以将两个数据集中的图例句柄组合到一个图例句柄中.

正如评论中所指出的,您还可以使用代理定义任意图例句柄.

最后,无论图表中绘制的数据如何,您都可以准确定义要在图例中显示的句柄和标签.

请参阅下面的MWE,其中说明了上述要点:

import matplotlib.pyplot as plt

import numpy as np

plt.close('all')

# Gererate some datas:

x = np.random.rand(50)

y = np.arange(len(x))

# Plot data:

fig, ax = plt.subplots(figsize=(11, 4))

fillA = ax.fill_between(y, x-0.25, 0.5, color='darkolivegreen', alpha=0.65, lw=0)

fillB = ax.fill_between(y, x, 0.5, color='indianred', alpha=0.75, lw=0)

linec, = ax.plot(y, np.zeros(len(y))+0.5, color='blue', lw=1.5)

linea, = ax.plot(y, x, color='orange', lw=1.5)

lineb, = ax.plot(y, x-0.25, color='black', lw=1.5)

# Define an arbitrary legend handle with a proxy:

rec1 = plt.Rectangle((0, 0), 1, 1, fc='blue', lw=0, alpha=0.25)

# Generate the legend:

handles = [linea, lineb, linec, fillA, fillB, (fillA, fillB),

rec1, (fillA, fillB, rec1)]

labels = ['a', 'b', 'c', 'A', 'B', 'A+B', 'C', 'A+B+C']

ax.legend(handles, labels, loc=2, ncol=4)

ax.axis(ymin=-1, ymax=2)

plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值