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

查看:193
本文介绍了如何在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 .

例如

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天全站免登陆