python matplotlib点划线-如何? [英] python matplotlib dash-dot-dot - how to?

查看:735
本文介绍了python matplotlib点划线-如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python和matplotlib生成图形输出.
有没有一种简单的方法来生成点对点线型?
我知道'--''-.'':'选项.不幸的是,'-..'不会导致点划线.
我已经看过set_dashes命令,但这似乎可以控制破折号的长度以及两个相邻破折号之间的间隔.
一种选择可能是在彼此顶部绘制两条线.一个破折号在破折号之间留有足够的空间-一个点破折号,与破折号一样大的点又宽又间隔,因此每个破折号之间有两个点.我毫不怀疑这可以做到,我只是希望有一种更简单的方法.
我是否忽略了一个选择?

I am using python and matplotlib to generate graphical output.
Is there a simple way to generate a dash-dot-dot line-style?
I am aware of the '--', '-.', and ':' options. Unfortunately, '-..' does not result in a dash-dot-dot line.
I have looked at the set_dashes command, but that seems to control the length of the dashes and the space between two adjacent dashes.
One option may be to plot two lines on top of each other; one dashed with ample space between the dashes - and one dotted, with the dots as large as the dashes are wide and spaced so that two dots are in between each of the dashes. I do not doubt this can be done, I am simply hoping for an easier way.
Did I overlook an option?

推荐答案

您可以定义自定义破折号:

import matplotlib.pyplot as plt

line, = plt.plot([1,5,2,4], '-')
line.set_dashes([8, 4, 2, 4, 2, 4]) 
plt.show()

[8, 4, 2, 4, 2, 4]表示

  • 8点,(破折号)
  • 优惠4分,
  • 2点(点)
  • 优惠4分,
  • 2点(点)
  • 折4分.

@Achim指出,您还可以指定dashes参数:

@Achim noted you can also specify the dashes parameter:

plt.plot([1,5,2,4], '-', dashes=[8, 4, 2, 4, 2, 4])
plt.show()

产生与上面所示相同的结果.

produces the same result shown above.

这篇关于python matplotlib点划线-如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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