python中plot不能显示标签_Python Matplotlib stackplot中的标签区域

我想在matplotlib stackplot的区域内生成标签.我会选择标记用于绑定该区域的线.考虑这个例子:

import numpy as np

from matplotlib import pyplot as plt

fnx = lambda : np.random.randint(5, 50, 10)

x = np.arange(10)

y1, y2, y3 = fnx(), fnx(), fnx()

areaLabels=['area1','area2','area3']

fig, ax = plt.subplots()

ax.stackplot(x, y1, y2, y3)

plt.show()

这产生:18lG5.png

但我想生产这样的东西:

CZcoG.png

matplotlib等高线图具有这种类型的标记功能(尽管在等高线图的情况下标记了线).

任何帮助(甚至重定向到我可能错过的帖子)都表示赞赏.

解决方法:

啊,启发式.像这样的东西?:

import numpy as np

from matplotlib import pyplot as plt

length = 10

fnx = lambda : np.random.randint(5, 50, length)

x = np.arange(length)

y1, y2, y3 = fnx(), fnx(), fnx()

areaLabels=['area1','area2','area3']

fig, ax = plt.subplots()

ax.stackplot(x, y1, y2, y3)

loc = y1.argmax()

ax.text(loc, y1[loc]*0.25, areaLabels[0])

loc = y2.argmax()

ax.text(loc, y1[loc] + y2[loc]*0.33, areaLabels[1])

loc = y3.argmax()

ax.text(loc, y1[loc] + y2[loc] + y3[loc]*0.75, areaLabels[2])

plt.show()

在测试运行中是好的:

naEP8.png

BaZ04.png

P2IJW.png

寻找最佳位置可能更加漂亮 – 也许人们希望x_n,x_(n 1)具有最高的平均值.

标签:python,matplotlib,plot,stacked-chart,stacked-area-chart

来源: https://codeday.me/bug/20190623/1273170.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值