Doc*_*ada 5 python plot matplotlib stacked-area-chart stacked-chart
我想在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()
Run Code Online (Sandbox Code Playgroud)
但是我想产生这样的东西:
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()
Run Code Online (Sandbox Code Playgroud)
在测试运行中这是可以的:
找到最好的loc
可能会更有趣——也许人们想要的x_n, x_(n+1)
是平均值最高的。
归档时间: |
|
查看次数: |
2642 次 |
最近记录: |