我可以在 matplotlib 中循环显示线条样式吗

编程入门 行业动态 更新时间:2024-10-25 23:35:12
本文介绍了我可以在 matplotlib 中循环显示线条样式吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道如何在 matplotlib 中循环显示颜色列表.但是是否可以对线条样式(普通、虚线、虚线等)做类似的事情?我需要这样做,以便我的图表在打印时更容易阅读.任何建议如何做到这一点?

I know how to cycle through a list of colors in matplotlib. But is it possible to do something similar with line styles (plain, dotted, dashed, etc.)? I'd need to do that so my graphs would be easier to read when printed. Any suggestions how to do that?

推荐答案

这样的事情可能会奏效:

Something like this might do the trick:

import matplotlib.pyplot as plt from itertools import cycle lines = ["-","--","-.",":"] linecycler = cycle(lines) plt.figure() for i in range(10): x = range(i,i+10) plt.plot(range(10),x,next(linecycler)) plt.show()

结果:

编辑更新版本 (v2.22)

import matplotlib.pyplot as plt from cycler import cycler # plt.figure() for i in range(5): x = range(i,i+5) linestyle_cycler = cycler('linestyle',['-','--',':','-.']) plt.rc('axes', prop_cycle=linestyle_cycler) plt.plot(range(5),x) plt.legend(['first','second','third','fourth','fifth'], loc='upper left', fancybox=True, shadow=True) plt.show()

有关更多详细信息,请参阅 matplotlib 教程使用循环仪进行造型"要查看输出,请单击显示图"

For more detailed information consult the matplotlib tutorial on "Styling with cycler" To see the output click "show figure"

更多推荐

我可以在 matplotlib 中循环显示线条样式吗

本文发布于:2023-11-06 14:39:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563971.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线条   样式   matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!