matplotlib步骤功能中的线型 [英] Linestyle in matplotlib step function

查看:209
本文介绍了matplotlib步骤功能中的线型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将matplotlib步骤功能中的线型设置为虚线,点线等?

Is it possible to set the linestyle in a matplotlib step function to dashed, dotted, etc.?

我尝试过:

step(x, linestyle='--'), 
step(x, '--')

但这没有帮助.

推荐答案

从mpl 1.3.0开始,此问题已在上游固定

As of mpl 1.3.0 this is fixed upstream

由于step似乎忽略了linestyle,因此您必须稍作调整.如果您查看step在下面的操作,它只是用于绘图的薄包装.

You have to come at it a bit sideways as step seems to ignore linestyle. If you look at what step is doing underneath, it is just a thin wrapper for plot.

您可以通过直接与plot交谈来做您想做的事情:

You can do what you want by talking to plot directly:

import matplotlib.pyplot as plt

plt.plot(range(5), range(5), linestyle='--', drawstyle='steps')
plt.plot(range(5), range(5)[::-1], linestyle=':', drawstyle='steps')
plt.xlim([-1, 5])
plt.ylim([-1, 5])

['steps', 'steps-pre', 'steps-mid', 'steps-post']drawstyle的有效值,并控制绘制步骤的位置.

['steps', 'steps-pre', 'steps-mid', 'steps-post'] are the valid values for drawstyle and control where the step is drawn.

请求,我个人认为这是一个错误.

Pull request resulting from this question, I personally think this is a bug. [edit: this has been pulled into master and should show up in v1.3.0].

这篇关于matplotlib步骤功能中的线型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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