Matplotlib.pyplot 创建图形、在图形中创建创建一个绘图区域、在绘图区域中你那个绘制一些线、在图形中添加标签之类

画二维平面图

x = np.arange(0, 10, 2)
y1 = x
y2 = x ** 2
plt.plot(x, y1, '*g--') #g 表示颜色
plt.show()

同一个坐标系里画多条线段

import matplotlib.pyplot as plt
import numpy as np x = np.arange(0, 10, 2)
y1 = x
y2 = x ** 2 # 正常显示中文
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei'] plt.xlabel('自变量') # 若是使用 汉字,则显示出错
plt.ylabel('因变量')
plt.plot(x, y1, '*g--', y2, '^b-')
plt.legend(['y=x', '$y=x^2$'], loc='upper right') # 显示每条线段的解释, $$ 里是 LaTeX语句
# 保存图片
plt.savefig('./Big Title.png')
# 防止图片部分缺失 方法一 增大画布
fig = plt.figure(figsize=(8,4))
# 防止图片部分缺失 方法一 紧致布局
plt.tight_layout()
#增大分辨率
plt.savefig('./Big Title.png', dpi=400)
plt.show()

分别放两个框中

import matplotlib.pyplot as plt
import numpy as np x = np.arange(0, 10, 2)
y1 = x
y2 = x ** 2
# 1.创建画板fig
fig = plt.figure()
# 参数解释,前两个参数 1,2 表示创建了一个一行两列的框 第三个参数表示当前所在的框
ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(1, 2, 2)
ax1.plot(x, y1, '*--', color="tab:blue")
ax2.plot(x, y2, '^-', color='tab:orange')
plt.show()

函数封装

import matplotlib.pyplot as plt

def show_plot(x_name: list, precision: list, recall: list, f1: list, AUC: list, path):
plt.plot(x_name, precision, 'or-', recall, '^g-', f1, '*b-', AUC, '.y-.')
plt.legend(['precision', 'recall', 'f1', 'AUC'], loc='upper right')
plt.savefig(path, dpi=300)
plt.show()
pass x_name = ['model1', 'model2', 'model3', 'model4'] y1 = [0.5, 0.6, 0.8, 0.9]
y2 = [0.6, 0.6, 0.85, 0.92]
y3 = [0.7, 0.66, 0.82, 0.91]
y4 = [0.8, 0.7, 0.82, 0.84, 0.93]
show_plot(x_name, y1, y2, y3, y4, r'test.png')

画多条曲线

import numpy as np
import matplotlib.pyplot as plt fig1 = plt.figure(num=1, figsize=(7, 5))
x = np.linspace(0.0, np.pi * 2, 20)
y = np.sin(x) plt.plot(x, y, 'rx-', x, 2 * x, 'go-.') # 每条都指定x轴数据 fig2 = plt.figure(num=2)
plt.plot(x, y, 'rx-', 2 * x, 'go-.') # 一条指定x轴数据,其他不指定 fig2 = plt.figure(num=3)
plt.plot(y, 'rx-', 2 * x, 'go-.') # 都不指定
plt.show()

说明

format_string 控制曲线的格式字符串,可选,由颜色字符风格字符和标记字符组成

颜色

字符 说明 字符 说明 字符 说明
'r' 红色 'g' 绿色 'b' 蓝色
'c' 青绿色 'k' 黑色 'y' 黄色
'w' 白色 'm' 洋红色

风格

字符 说明 字符 说明 字符 说明 字符 说明
'-' 实线 '–' 破折线 '-.' 点画线 ':' 虚线

风格

字符 说明 字符 说明 字符 说明
'.' 点标记 ',' 像素标记 'o' 实心圈标记
'v' 倒三角标记 '^' 上三角标记 '>' 右三角标记
'<' 左三角标记 'h' 竖六边形标记 'H' 横六边形标记
'+' 十字标记 'x' x标记 'D' 菱形标记
'd' 瘦菱形标记 '|' 垂直线标记 '*' 星形标记
'p' 实心五角标记 's' 实心方形标记 '4' 右花三角标记
'3' 左花三角标记 '2' 上花三角标记 '1' 下花三角标记

使用方法

plt.plot(x, y,'g')
plt.plot(x, y,color='green') plt.plot(x, y,'go')
plt.plot(x, y,color='green',marker = 'o') plt.plot(x, y,'go-.')

Matplotlib.pyplot.plot 绘图的更多相关文章

  1. matplotlib.pyplot.plot详解

    参考资料: https://blog.csdn.net/baidu_41902768/article/details/80686608 之前的随笔也有说过,matplotlib是python中一个非常 ...

  2. scikit-learn:matplotlib.pyplot经常使用绘图功能总结(1)

    參考:http://matplotlib.org/api/pyplot_api.html 绘图功能总结(2):http://blog.csdn.net/mmc2015/article/details/ ...

  3. python matplotlib.pyplot学习记录

    matplotlib是python中很强大的绘图工具,在机器学习中经常用到 首先是导入 import matplotlib.pyplot as plt plt中有很多方法,记录下常用的方法 plt.p ...

  4. matplotlib作图——plot() 线图

    线图 #定义 matplotlib.pyplot.plot() plot([x], y, [fmt], data=None, **kwargs) plot([x], y, [fmt], [x2], y ...

  5. 在绘图的时候import matplotlib.pyplot as plt报错:ImportError: No module named '_tkinter', please install the python-tk package

    在绘图的时候import matplotlib.pyplot as plt报错:ImportError: No module named '_tkinter', please install the ...

  6. matplotlib plot 绘图函数发生阻塞(block)时的解决方法

    Is there a way to detach matplotlib plots so that the computation can continue? 在一般编辑器中: from matplo ...

  7. 使用matplotlib.pyplot中plot()绘制折线图

    1.函数形式 plt.plot(x, y, format_string, **kwargs) x轴数据,y轴数据,format_string控制曲线的格式字串(format_string 由颜色字符, ...

  8. matplotlib.pyplot 绘图详解 matplotlib 安装

    apt-get install python-matplotlib 转载自: http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086. ...

  9. 服务器上使用matplotlib.pyplot绘图

    在linux服务器端执行python脚本,有时候需要画图,但是linux没有GUI界面,因此需要在导入matplotlib.pyplot库之前先执行 import matplotlib as mpl ...

  10. 【搬砖】【Python数据分析】Pycharm中plot绘图不能显示出来

    最近在看<Python数据分析>这本书,而自己写代码一直用的是Pycharm,在练习的时候就碰到了plot()绘图不能显示出来的问题.网上翻了一下找到知乎上一篇回答,试了一下好像不行,而且 ...

随机推荐

  1. Android笔记--SQL

    SQL基本语法 基本语法在Python和Java那里都已经重复过了,这里就不再重复了 SQLiteDatabase--SQLite的数据库管理类 主要分为以下3类: 管理类 相关实现: 事务类 数据库 ...

  2. Spring--案例:数据源对象管理

    案例:数据源对象管理 对于已经学过数据库的我来说,这看起来就像是连接数据库的操作: 就像javaweb项目里面的db.properties文件的使用一样,我们需要先导入一个包,(我用的是Maven项目 ...

  3. AD域安全攻防实践(附攻防矩阵图)

    以域控为基础架构,通过域控实现对用户和计算机资源的统一管理,带来便利的同时也成为了最受攻击者重点攻击的集权系统. 01.攻击篇 针对域控的攻击技术,在Windows通用攻击技术的基础上自成一套技术体系 ...

  4. 后疫情时代,RTE“沉浸式”体验还能这么玩?丨RTE 2022 编程挑战赛赛后专访

    前言 9 月 17 日,由声网.环信与 RTE 开发者社区联合主办的"RTE 2022 编程挑战赛"圆满落幕.从 300+ 支参赛队伍中冲出重围的 27 支决赛队伍,在元宇宙中用精 ...

  5. springboot--yaml数据读取的三种方式

    结果:

  6. IDEA集成Gitee

    配置Git 在设置里面点击Git,点击选择git安装目录下的bin目录下的git.exe,点击Test,出现版本号,证明配置成功. 配置码云 在设置里面按照下图步骤,即可成功配置码云 安装Gitee插 ...

  7. groovy, Scala和kotlin区别

    所谓Scala的目的是什么?事实上Scala作者Martin Odesky他在<Programming in Scala>中写到,Scala的目的是为了更好的融合OO与FP,确实,不是取代 ...

  8. Springboot一些常用注解

    Springboot启动注解 @SpringbootApplication 这个注解是Springboot最核心的注解,用在Springboot的主类上,标识这是一个Springboot应用,用来开启 ...

  9. 在 Rainbond 上使用在线知识库系统zyplayer-doc

    zyplayer-doc 是一款适合企业和个人使用的WIKI知识库管理工具,提供在线化的知识库管理功能,专为私有化部署而设计,最大程度上保证企业或个人的数据安全,可以完全以内网的方式来部署使用它. 当 ...

  10. Java中ThreadLocal的用法和原理

    用法 隔离各个线程间的数据 避免线程内每个方法都进行传参,线程内的所有方法都可以直接获取到ThreadLocal中管理的对象. package com.example.test1.service; i ...