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

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

)。

我的公众号:“

pythonic生物人

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

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

写作时间:2020-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官网上就有,请戳:

https://matplotlib.org/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生物人",持续分享数据科学和生物信息干货,欢迎来看看。

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

  1. python地图上动态显示数据_Python可视化笔记之folium交互地图

    leftlet给R语言提供了很好用的交互式动态地图接口,其在Python中得API接口包名为folium(不知道包作者为何这样起名字,和leaflet已经扯不上关系了),可以满足我们平时常用的热力图. ...

  2. python plot 增加标记线,matplotlib初学:这样画折线图和添加标注、箭头

    原标题:matplotlib初学:这样画折线图和添加标注.箭头 用matplotlib 画折线图,一般使用plt.plot函数,它的具体格式为: plt.plot(x,y1, '颜色线条') 默认线条 ...

  3. python plot方法的使用_Python bokeh.plotting.figure.step()用法及代码示例

    Bokeh是Python中的数据可视化库,可提供高性能的交互式图表和绘图,并且可以通过笔记本,html和服务器等各种介质获取输出. Figure类创建一个新的Figure进行绘制.它是Plot的子类, ...

  4. python绘制散点图的步骤_python绘制散点图并标记序号的方法

    python绘制散点图并标记序号的方法 实现二维平面上散点的绘制,并可以给每个散点标记序号或者名称: import numpy as np import matplotlib.pyplot as pl ...

  5. python自动标注autocad坐标_python 可视化 二维坐标标注等等

    基本画图操作: import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3,3,50) y1 = 2*x+1 y2 = ...

  6. python编写人口预测图_Python可视化神器——pyecharts(实例之人口地图)

    官方教程:http://pyecharts.herokuapp.com/ pyecharts 是一个用于生成 Echarts 图表的类库.Echarts 是百度开源的一个数据可视化 JS 库.用 Ec ...

  7. python不同时间周期k线_Python量化交易基础讲堂-股票分笔数据跨周期处理

    <Python实战-构建基于股票的量化交易系统>小册子主要侧重于 Python 实战讲解,但在内容设计上提供了前置基础章节帮助读者快速掌握基础工具的使用.同时我们会持续更新一些关于Pyth ...

  8. python的matplotlib背景线_python中matplotlib的颜色及线条 控制

    https://www.cnblogs.com/darkknightzh/p/6117528.html https://blog.csdn.net/qq_34337272/article/detail ...

  9. 用python提取图片主要颜色_Python可视化|09-使用python和R提取图片颜色绘图(五-颜色使用完结篇)...

    本文是继前面四篇python可视化颜色使用的完结篇,介绍如何使用python提取图片中的颜色绘图: 如果你不想使用前人设定好的色号或者colormap,想自己从好看的图片中提取颜色,请往下看: 1.颜 ...

  10. python如何进入编程界面_Python可视化界面编程入门

    Python可视化界面编程入门具体实现代码如所示: (1)普通可视化界面编程代码入门: import sys from PyQt5.QtWidgets import QWidget,QApplicat ...

最新文章

  1. 怎么通过ip连接oracle,Oracle 无法通过IP连接问题
  2. DCS系统接地应用讨论
  3. python有道翻译-Python版有道翻译
  4. 第01讲:必知必会,掌握 HTTP 基本原理
  5. C语言 abort 函数 - C语言零基础入门教程
  6. java 扩展数据类型_与Java的初遇——数据类型扩展
  7. 阿里云物联网平台python开发手册_阿里云物联网平台之云端API调用(即云端开发教程)...
  8. 去掉输入法上的CH和EN
  9. 二级c语言上机题库下载,二级C语言上机题库(全).doc
  10. VMWare共享文件夹的使用
  11. java开发高薪工程师,Java开发工程师如何获得高薪
  12. 四大步骤,彻底关闭Win10自动更新
  13. AliOS-Things--Visual Studio Code Windows环境搭建 EMW3060
  14. 汉堡按钮的制作以及其中的问题
  15. teracopy php,Unraid 升级到 UnRaid 6.0的详细操作步骤(三)
  16. web前端面试宝典——带你直击面试重难点(40个经典题目,涵盖近90%的考点,码字2w,干货满满!)
  17. Web Components 的使用,从入门到基础
  18. CUIT循迹智能车竞赛
  19. 最新!2023年工程测量乙级测绘资质申请标准
  20. 新版Dell本本BIOS设置完全手册--U盘装系统bios设置教程

热门文章

  1. Vue学习手记02-路由创建
  2. VS 2017 + EF6 + MySQL5.7 建立实体模型闪退问题
  3. 假期周进度总结(三)
  4. 动态路由之OSPF协议综合实验
  5. ado.net EF学习系列----深入理解查询延迟加载技术(转载)
  6. Windows Server 2008 Active Directory建置實務(附CD)
  7. 基于jsp+servlet图书管理系统之后台用户信息修改操作
  8. iOS 控制器View加载顺序详细版
  9. C# 从类库中获取资源图片,把图片资源保存到类库中
  10. 从分析性数据库ADS中导出数据