【python】Matplotlib作图常用marker类型、线型和颜色

您所在的位置:网站首页 常见的动线设计方法有哪些种类 【python】Matplotlib作图常用marker类型、线型和颜色

【python】Matplotlib作图常用marker类型、线型和颜色

2024-07-13 17:41| 来源: 网络整理| 查看: 265

python作图中常常会考虑用什么颜色、marker、线型,这个资料查了又查,所以自己总结在这个地方,以便常用。

ls 或者 linestyle:设定折线的格式,[文字表述版为‘ solid’, 'dashed', 'dashdot', 'dotted'],符号表述版[ '-', '--', '-.', ':'];lw 或者 linewidth:设定折线的宽度,drawstyle:指定画图的格式,比如drawstyle='steps-post',即阶梯图线;ms 或者 markersize:设定大小;mec 或者 markeredgecolor:设定边框的颜色;mew 或者 markeredgewidth:设定边框粗细的值;mfc 或者 markerfacecolor:设定填充的颜色;ax1.set_xlable:设定ax1(子图)x坐标的名称ax1.set_ylable:设定ax1(子图)y坐标的名称其他待续参数 from numpy.random import randn import matplotlib.pyplot as plt data = randn(30).cumsum() plt.plot(data, 'ro--', drawstyle='steps-post') plt.show()

 

一、常用marker表示 1.普通marker

这类普通marker直接marker ='^'就可以用了

2.高级marker

这类高级marker使用marker ='$\circledR$'来调用

形状marker名称ϖ\varpiϱ\varrhoς\varsigmaϑ\varthetaξ\xiζ\zetaΔ\DeltaΓ\GammaΛ\LambdaΩ\OmegaΦ\Phi Π\Pi\Pi\PsiΣ\SigmaΘ\ThetaΥ\UpsilonΞ\Xi℧\mho∇\nabla        ℵ\alephℶ\bethℸ\dalethℷ\gimel⇓\Downarrow⇑\Uparrow‖ \Vert↓\downarrow〈\langle⌈\lceil⌊\lfloor⌞\llcorner⌟\lrcorner〉\rangle⌉\rceil⌋\rfloor⌜\ulcorner↑\uparrow⌝\urcorner⋂\bigcap⋃\bigcup⨀\bigodot⨁\bigoplus⨂\bigotimes⨄\biguplus⋁\bigvee⋀\bigwedge∐\coprod∫\int∮\oint∏\prod∑\sum 3.自定义marker import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['SimHei'] # 用于显示中文 plt.rcParams['axes.unicode_minus'] = False # 用于显示中文 plt.figure(dpi=200) #常规marker使用 plt.plot([1,2,3],[1,2,3],marker=4, markersize=15, color='lightblue',label='常规marker') plt.plot([1.8,2.8,3.8],[1,2,3],marker='2', markersize=15, color='#ec2d7a',label='常规marker') #非常规marker使用 #注意使用两个$符号包围名称 plt.plot([1,2,3],[4,5,6],marker='$\circledR$', markersize=15, color='r', alpha = 0.5 ,label='非常规marker') plt.plot([1.5,2.5,3.5],[1.25,2.1,6.5],marker='$\heartsuit$', markersize=15, color='#f19790', alpha=0.5,label='非常规marker') plt.plot([1,2,3],[2.5,6.2,8],marker='$\clubsuit$', markersize=15, color='g', alpha=0.5,label='非常规marker') #自定义marker plt.plot([1.2,2.2,3.2],[1,2,3],marker='$666$', markersize=15, color='#2d0c13',label='自定义marker') plt.legend(loc='upper left') for i in ['top','right']: plt.gca().spines[i].set_visible(False)

作图结果为:

二、常用线型 1.字符型linestyle

共有四种:

linestyle_str = [ ('solid', 'solid'), # Same as (0, ()) or '-';solid’, (0, ()) , '-'三种都代表实线。 ('dotted', 'dotted'), # Same as (0, (1, 1)) or '.' ('dashed', 'dashed'), # Same as '--' ('dashdot', 'dashdot')] # Same as '-.'

2.元组型linestyle

可以通过修改元组中的数字来呈现出不同的线型,因此可以构造出无数种线型。

linestyle_tuple = [ ('loosely dotted', (0, (1, 10))), ('dotted', (0, (1, 1))), ('densely dotted', (0, (1, 2))), ('loosely dashed', (0, (5, 10))), ('dashed', (0, (5, 5))), ('densely dashed', (0, (5, 1))), ('loosely dashdotted', (0, (3, 10, 1, 10))), ('dashdotted', (0, (3, 5, 1, 5))), ('densely dashdotted', (0, (3, 1, 1, 1))), ('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))), ('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))), ('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))]

线型使用代码:

import matplotlib.pyplot as plt plt.figure(dpi=120) #字符型linestyle使用方法 plt.plot([1,2,3],[1,2,13],linestyle='dotted', color='#1661ab', linewidth=5, label='字符型线型:dotted') #元组型lintstyle使用方法 plt.plot([0.8,0.9,1.5],[0.8,0.9,21.5],linestyle=(0,(3, 1, 1, 1, 1, 1)), color='#ec2d7a', linewidth=5, label='元组型线型:(0,(3, 1, 1, 1, 1, 1)') for i in ['top','right']: plt.gca().spines[i].set_visible(False) #自定义inestyle plt.plot([1.5,2.5,3.5],[1,2,13],linestyle=(0,(1,2,3,4,2,2)), color='black', linewidth=5, label='自定义线型:(0,(1,2,3,4,2,2)))') plt.plot([2.5,3.5,4.5],[1,2,13],linestyle=(2,(1,2,3,4,2,2)), color='g', linewidth=5, label='自定义线型:(1,(1,2,3,4,2,2)))') plt.legend()

作图结果为:

3.元组型详解

上图中线型(0,(1,2,3,4,2,2))每个数字是什么意思?理解每个数字的意思就可以自定义线型了。

第一个0的意义,比较黑色和绿色线型即可知道

1,2 第一小段线宽1磅,第一和第二段之间距离2磅

3,4 第二小段线宽3磅,第二和第三段之间距离4磅

2,2 第三小段线宽2磅,第三和第四段之间距离2磅

三、常用颜色

装了seaborn扩展的话,在字典seaborn.xkcd_rgb中包含所有的xkcd crowdsourced color names。

以上部分内容参考:pythonic生物人,链接:https://www.jianshu.com/p/7543b925bdb8



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3