在matplotlib中更改虚线的虚线间距 [英] Change spacing of dashes in dashed line in matplotlib

查看:1110
本文介绍了在matplotlib中更改虚线的虚线间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中,使用matplotlib,有一种方法可以更改不同线型的破折号距离,例如,使用以下命令:

In Python, using matplotlib, is there a way to change the distance of the dashes for different linestyles, for example, using the following command:

plt.plot(x,y,linestyle='--')

推荐答案

您可以使用plot命令中的dashes=(length, interval space)参数直接指定破折号的长度/间隔.

You can directly specify the dashes length/space using the dashes=(length, interval space) argument inside the plot command.

import matplotlib.pyplot as plt

fig,ax = plt.subplots()
ax.plot([0, 1], [0, 1], linestyle='--', dashes=(5, 1)) #length of 5, space of 1
ax.plot([0, 1], [0, 2], linestyle='--', dashes=(5, 5)) #length of 5, space of 5
ax.plot([0, 1], [0, 3], linestyle='--', dashes=(5, 10)) #length of 5, space of 10
ax.plot([0, 1], [0, 4], linestyle='--', dashes=(5, 20)) #length of 5, space of 20

这篇关于在matplotlib中更改虚线的虚线间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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