如何在 Python 中使用 Matplotlib 绘制阶跃函数? [英] How do I plot a step function with Matplotlib in Python?

查看:59
本文介绍了如何在 Python 中使用 Matplotlib 绘制阶跃函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很容易,但我刚刚开始玩 matplotlib 和 python.我可以画一条线或一个散点图,但我不知道如何做一个简单的阶跃函数.非常感谢任何帮助.

This should be easy but I have just started toying with matplotlib and python. I can do a line or a scatter plot but i am not sure how to do a simple step function. Any help is much appreciated.

x = 1,2,3,4
y = 0.002871972681775004, 0.00514787917410944, 0.00863476098280219, 0.012003316194034325

推荐答案

看起来你想要 step.

It seems like you want step.

例如

import matplotlib.pyplot as plt

x = [1,2,3,4] 
y = [0.002871972681775004, 0.00514787917410944, 
     0.00863476098280219, 0.012003316194034325]

plt.step(x, y)
plt.show()

这篇关于如何在 Python 中使用 Matplotlib 绘制阶跃函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆