本文介绍了真的只有4种Matplotlib线型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在matplotlib中寻找新的线型,唯一可用的线型是[-",-",-.",:",]. (样式选项['','','None',]不起作用,因为它们只是隐藏行.)

I've been looking for new line styles in matplotlib, and the only line styles available are ["-", "--", "-.", ":",]. (The style options ['', ' ', 'None',] don't count because they just hide the lines.)

在Matplotlib pyplot中真的只有4种线型吗?有没有增加更多线型的扩展程序?有没有一种自定义线条样式的方法?像这样的三种字符线条样式怎么样?

Are there really only 4 line styles in Matplotlib pyplot? Are there any extensions that add further line styles? Is there a way to customise line styles? How about some three character line styles like:

  • '-.':破折号
  • '-..':点划线点
  • '...':点点(空格)
  • "xxx":x在一行中
  • '\/':之字形,即'\/\/\/\/'
  • '::':并行点,即:::::

这些只是扩大线型范围的一些想法.

These are just some ideas to expand the range of line styles.

推荐答案

您可以使用dashes kwarg设置自定义破折号样式.

You can use the dashes kwarg to set custom dash styles.

文档:

以下是根据您的一些建议提供的一些示例.显然,您可以通过多种方式自定义此内容.

Here's some examples based on a few of your suggestions. Obviously there are many more ways you could customise this.

import matplotlib.pyplot as plt

fig,ax = plt.subplots(1)

# 3 dots then space
ax.plot(range(10), range(10),     dashes=[3,6,3,6,3,18],  lw=3,c='b')

# dash dash dot
ax.plot(range(10), range(0,20,2), dashes=[12,6,12,6,3,6], lw=3,c='r')

# dash dot dot
ax.plot(range(10), range(0,30,3), dashes=[12,6,3,6,3,6],  lw=3,c='g')

这篇关于真的只有4种Matplotlib线型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:11