我想演示用分段常数阶跃函数逼近连续函数的积分.
生成的绘图应如下所示:
我有一个工件常数函数,我的问题是我不知道如何绘制它,因为典型的候选者似乎不起作用:
它看起来类似于直方图,但生成方式非常不同.
从我所看到的情况来看,条形图与数字线不一致.
The plt.step()
method on the other hand does not include the bins/bars; using it I got this so far:
使用此代码
kwargs = dict(drawstyle = 'steps-mid')
plt.plot(times, f(times), '-')
plt.plot(times, fitted_values, **kwargs)
是否有一个专门的函数,或我忽略的一些kwargs参数,可以在这里绘制出我需要的内容?
Edit:
Thank you for the answer @Stef ! I just tried this solution and recognized an issue with a bar-plot here.
plt generates a bar for every value in the times
array. Now I get this result: