【发布时间】:2021-03-10 13:37:46
【问题描述】:
图例中的颜色与我的堆栈图上的颜色混合在一起。看起来,这似乎是默认设置(因为我没有触及任何颜色设置)。我将如何解决这个问题?有没有办法给我的图例一个背景颜色?我已经尝试过使用facecolor 参数。
这是我的代码:
from matplotlib import pyplot as plt
days = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# hours worked each day on the project
dev1 = [8, 6, 5, 5, 4, 2, 1, 1, 0]
dev2 = [0, 1, 2, 2, 2, 4, 4, 4, 4]
dev3 = [0, 1, 1, 1, 2, 2, 3, 3, 4]
plt.style.use('fivethirtyeight')
labels = ['Developer 1', 'Developer 2', 'Developer 3']
plt.stackplot(days, dev1, dev2, dev3, labels=labels)
plt.legend(loc=(0.05, 0.07))
# plt.legend(loc=(0.05, 0.07), facecolor='white') I have tried this as well
plt.title('My Awesome Stack Plot')
plt.tight_layout()
plt.show()
【问题讨论】:
-
很奇怪。我得到this output。
-
会不会跟版本有关?我过去曾短暂使用过 matplotlib,这就是我记忆中的方式(默认情况下)。我还应该提到,我已经在 jupyter notebooks 和 jupyter lab 中尝试过这个
标签: python matplotlib jupyter-notebook jupyter-lab