300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > python plot 增加标记线_Python可视化| matplotlib04-掌握标记和线型的使用 一文 marker linestyle...

python plot 增加标记线_Python可视化| matplotlib04-掌握标记和线型的使用 一文 marker linestyle...

时间:2018-08-08 05:34:57

相关推荐

python plot 增加标记线_Python可视化| matplotlib04-掌握标记和线型的使用 一文 marker linestyle...

详细介绍Matplotlib绘图时标记(marker)和线性(linestyle)使用方法、以及自定义marker和linestyle的方法(

这些marker和linestyle适合整个python生态绘图用,不仅仅是matplotlib,seaborn等其它绘图库通用

)。

我的公众号:“

pythonic生物人

“,持续分享数据科学和生物信息干货。

版权声明:“pythonic生物人“原创文章,欢迎收藏、点赞、关注三连,转载请标明出处,白嫖是不能原谅的!

写作时间:-06-20,有问题可留言或者我的公众号。

1、标记(marker)

matplotlib入门级marker

matplotlib一般marker位于matplotlib.lines import Line2D中,共计

30+

种,可以输出来康康有哪些:

from matplotlib.lines import Line2D

print([m for m, func in Line2D.markers.items()

if func != 'nothing' and m not in Line2D.filled_markers] + list(Line2D.filled_markers))

['.', ',', '1', '2', '3', '4', '+', 'x', '|', '_', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 'o', 'v', '^', '', '8', 's', 'p', '*', 'h', 'H', 'D', 'd', 'P', 'X'

]

这些marker都长什么样纸了,来康康:

37种marker,一般绘图可以完全满足了,如果您说不满足,想要更酷炫的,比如说下面这种,

往下看,都给你,让您满足的溢出来。

matplotlib高手级marker

matplotlib官网上就有,请戳:

/tutorials/text/mathtext.html

。一时冲动爬了下辣个网站,有

400+

种【

感兴趣可以公众号私信我发给您

】,长如下这样的:

可以显示的形状 marker名称

ϖ\varpi

ϱ\varrho

ς\varsigma

ϑ\vartheta

ξ\xi

ζ\zeta

Δ\Delta

Γ\Gamma

Λ\Lambda

Ω\Omega

Φ\Phi

Π\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

\vert

{\{

\|

}\}

]]

|

⋂\bigcap

⋃\bigcup

⨀\bigodot

⨁\bigoplus

⨂\bigotimes

⨄\biguplus

⋁\bigvee

⋀\bigwedge

∐\coprod

∫\int

∮\oint

∏\prod

∑\sum

选取部分marker画个图

matplotlib高高手级marker

当然,最高境界是想咋滴就咋滴,自己造一个形状;

自定义marker,使用两个美元符号($)包围你想要显示的东东,目前试验了666不错,可以自行实验。

matplotlib中marker怎么使用

非常简单,入门级marker使用时,marker=

marker名称;

高手级和自定义级marker使用时,marker=$

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)

2 、线型(linestyle)

线性 (linestyle)可分为字符串型的元组型的:

字符型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 '-.'

元组型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()

元组线型详解

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

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

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

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

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

3、参考资料

5、我的公众号

"pythonic生物人",持续分享数据科学和生物信息干货,欢迎来看看。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。