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字典替换值

python - 从使用pivot_table()创建的df中删除索引名称

python - 基于DataFrame列的操作

python - 迭代类属性

python - 我应该如何连接字典的 user_id 和模型的 user_id?

python - 来自 pandas 数据框的 seaborn 时间序列

python - 如何在seaborn的猫图中添加网格线?

python - 分布直方图中的加权条柱

python - 根据 ax.text 的值更改文本颜色

python - 来自 pandas 数据框的不同大小、标记和颜色的散点图