考虑下面的StPoTrk,使用MyPultLIB使用PyPrPig使用^ {CD1>}创建。有两类变量,收入和支出。它们都列在同一个图例中。
我想要两个单独的图例,一个是关于收入的,一个是关于支出的。已经有了one example of how this can be done on this site,但是它不适用于由stackplot()
创建的PolyCollection
以下是一个带有单个图例的MWE:
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
xVector = range(3)
earnings = {'fare': [2, 4, 6], 'tip': [1, 2, 3]}
expenses = {'maintenance': [-0.5, -1, -1.5], 'gas': [-1, -1.5, -2]}
ax.stackplot(xVector, earnings.values(), labels=earnings.keys())
ax.stackplot(xVector, expenses.values(), labels=expenses.keys())
plt.legend(loc='upper left')
plt.xlabel('time')
plt.ylabel('currency')
plt.show()
使用当前版本的Matplotlib,可以按照this answer from a different thread实现多个图例,如下所示(颠倒图例条目的顺序也很简单)
相关问题 更多 >
编程相关推荐