Matplotlib图例中误差带的线条和阴影区域 [英] Line plus shaded region for error band in matplotlib's legend
本文介绍了Matplotlib图例中误差带的线条和阴影区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
但虚线和黄色区域按如下方式合并:
推荐答案
若要执行所需操作,您需要调用legend
将所需的两条线/补丁合并到一个项目中。
要了解如何在实践中做到这一点,请看一个简单的工作示例:
# Import libraries
import numpy as np
import matplotlib.pyplot as plt
# Create some fake data
xvalue = np.linspace(1,100,100)
pop_mean = xvalue
walker_pos = pop_mean + 10*np.random.randn(100)
# Do the plot
fig, ax = plt.subplots()
# Save the output of 'plot', as we need it later
lwalker, = ax.plot(xvalue, walker_pos, 'b-')
# Save output of 'fill_between' (note there's no comma here)
lsigma = ax.fill_between(xvalue, pop_mean+10, pop_mean-10, color='yellow', alpha=0.5)
# Save the output of 'plot', as we need it later
lmean, = ax.plot(xvalue, pop_mean, 'k--')
# Create the legend, combining the yellow rectangle for the
# uncertainty and the 'mean line' as a single item
ax.legend([lwalker, (lsigma, lmean)], ["Walker position", "Mean + 1sigma range"], loc=2)
fig.savefig("legend_example.png")
plt.show()
您可以查看Legend guide以跟踪正在发生的事情,并根据您的具体需要调整图例。
这篇关于Matplotlib图例中误差带的线条和阴影区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文