python - 如何使用 Seaborn 绘制阶跃函数?

标签 python seaborn

我想使用 Seaborn 制作类似于此的步骤图 matplotlib example

import seaborn as sns
x = [1,2,3,4]
y = [0.002871, 0.0051, 0.0086, 0.005]
sns.lineplot(x,y)

我可以使用drawstyle='steps-post'吗?

以下内容不起作用:sns.lineplot(x,y, drawstyle='steps-pre')

结果应如下所示: step plot

最佳答案

由于 sns.lineplot 的更多关键字参数被传递给 matplotlib 的绘图函数,因此您可以直接使用 drawstyle 参数。以下在seaborn 0.9.0和matplotlib 2.2.2中工作正常。

import matplotlib.pyplot as plt
import seaborn as sns
x = [1,2,3,4]
y = [0.002871, 0.0051, 0.0086, 0.005]
sns.lineplot(x,y, drawstyle='steps-pre')
plt.show()

enter image description here

或者类似地使用sns.lineplot(x,y,drawstyle='steps-post')

enter image description here

关于python - 如何使用 Seaborn 绘制阶跃函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51513570/

相关文章:

python - 在 sns.kdeplot 中对 Z 轴进行对数变换

python - 如何设置计数图顺序

python - 使用 read() 方法从 Amazon S3 读取大型 JSON 文件时出现内存错误

Python:如何免费获取股票数据(对于许多代码,如标准普尔 500)

python - 如何在 Mac 终端中使用命令行参数运行 exe 文件?

python - Seaborn 子图保留不同的 x 标签

sorting - 根据相似性度量(例如余弦相似性等)对 Holoviews 热图的列和行重新排序

python - 在 matplotlib 中实时绘图,同时执行需要时间的测量

python - 打印排序的字典键和排序的值

python - 如何在python中为绘图添加填充?