本文介绍了如何使用pyplot填充阶梯曲线下的区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已使用pyplot.step()
绘制了两条阶梯曲线,我想在这些曲线下方的区域进行阴影处理(最好使用透明阴影). pyplot.fill_between()
假定为线性插值,而我想查看步骤插值,如下所示:
I have plotted two step curves using pyplot.step()
, and I would like to shade in the area beneath these curves (ideally with transparent shading). pyplot.fill_between()
assumes linear interpolation, whereas I want to see step interpolation, as displayed below:
如何在这些曲线下方的区域中着色?透明的颜色会很棒,因为这样可以清楚地显示这些曲线重叠的位置.
How can I shade in the region beneath these curves? Transparent coloring would be great, as this would make clear where these curves overlap.
推荐答案
您可以使用fill_between的alpha值使其半透明.
You can use the alpha value of the fill_between to make it semi-transparent.
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,50,35)
y = np.random.exponential(1, len(x))
y2 = np.random.exponential(1, len(x))
plt.fill_between(x,y, step="pre", alpha=0.4)
plt.fill_between(x,y2, step="pre", alpha=0.4)
plt.plot(x,y, drawstyle="steps")
plt.plot(x,y2, drawstyle="steps")
plt.show()
这篇关于如何使用pyplot填充阶梯曲线下的区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!