📓
Study
  • README
  • Application
    • Contest
      • 竞赛trick
  • Basic Know
    • 半监督学习
    • 贝叶斯
      • 朴素贝叶斯分类器
    • 对抗训练
    • 概率图模型
      • CRF
      • HMM
      • 概率图模型
    • 关联分析
    • 归纳偏置
      • [什么是 Inductive bias(归纳偏置)?](BasicKnow/归纳偏置/什么是 Inductive bias(归纳偏置)?.md)
    • 聚类
    • 决策树
    • 绿色深度学习
    • 树模型&集成学习
      • 提升树
      • Ada Boost
      • [集成学习]
    • 特征工程
      • 数据分桶
      • 特征工程概述
      • 特征选择
      • LDA
      • PCA
    • 线性模型
      • 感知机
      • 最大熵模型
      • SVM
        • SVM支持向量机
      • 逻辑回归
      • 线性回归
    • 优化算法
      • 拉格朗日对偶性
      • 牛顿法
        • 牛顿法&拟牛顿法
      • 梯度下降法
        • 梯度下降算法
      • 优化算法
    • 预处理
      • [1-1]正则表达式
      • [1-2]文本预处理
      • [1-3]词性
      • [1-4]语法分析
      • [1-6]文本分类
      • [1-7]网络爬取
      • 【备用】正则表达式
      • 7.re模块
      • 词典匹配
      • 分词
      • 子表达式
      • Todo
    • 主题模型
      • LDA
    • Deep Learning
      • 反向传播
      • 梯度消失&梯度爆炸
      • Batch Size
      • 1.DLbasis
      • 小概念
      • MLstrategy
      • CNN
      • RNN及其应用
      • 关于深度学习实践
      • 神经网络概述
      • Batch Normalization
      • Program CNN
      • Program D Lbasis
      • Program DN Nimprove
      • Program Neural Style Transfer
      • Summer DL
    • EM算法
    • GAN
      • Gans In Action Master
    • GNN
      • 搜广推之GNN
      • Representation Learning
        • Anomalydetection
        • Conclusion
        • Others
        • Papernotes
        • Recommadation
    • k近邻法
      • K近邻
    • Language Model
      • 语言模型解码采样策略
      • [1-1][语言模型]从N-gram模型讲起
      • [1-2][语言模型]NNLM(神经网络语言模型)
      • [1-3][语言模型]基于RNN的语言模型
      • [1-4][语言模型]用N-gram来做完形填空
      • [1-5][语言模型]用KenLM来做完形填空
    • Loss Function
      • 常用损失函数
      • Focal Loss
      • softmax+交叉熵
    • Machine Learning
      • [基础]概念
      • 待整合
      • 交叉验证
      • 无监督学习
      • 优缺点
      • ML Yearning
      • SVD
    • Statistics Math
      • 程序员的数学基础课
      • 数学基础
      • 统计&高数
      • 统计题目
      • 线性代数
      • 组合数学
      • Discrete Choice Model
      • Nested Choice Model
  • Course Note
    • 基于TensorFlow的机器学习速成课程
      • [Key ML Terminology](CourseNote/基于TensorFlow的机器学习速成课程/Key ML Terminology.md)
    • 集训营
      • 任务说明
      • 算法实践1.1模型构建
      • 算法实践1.2模型构建之集成模型
      • 算法实践2.1数据预处理
    • 李宏毅机器学习
      • 10DNN训练Tips
        • Chapter 18
      • 16无监督学习
        • Chapter 25
    • 贪心NLP
      • 贪心NLP笔记
    • Cs 224 N 2019
      • [A Simple But Tough To Beat Baseline For Sentence Embeddings](CourseNote/cs224n2019/A Simple but Tough-to-beat Baseline for Sentence Embeddings.md)
      • [Lecture 01 Introduction And Word Vectors](CourseNote/cs224n2019/Lecture 01 Introduction and Word Vectors.md)
      • [Lecture 02 Word Vectors 2 And Word Senses](CourseNote/cs224n2019/Lecture 02 Word Vectors 2 and Word Senses.md)
      • [Lecture 03 Word Window Classification Neural Networks And Matrix Calculus](CourseNote/cs224n2019/Lecture 03 Word Window Classification, Neural Networks, and Matrix Calculus.md)
      • [Lecture 04 Backpropagation And Computation Graphs](CourseNote/cs224n2019/Lecture 04 Backpropagation and Computation Graphs.md)
      • [Lecture 05 Linguistic Structure Dependency Parsing](CourseNote/cs224n2019/Lecture 05 Linguistic Structure Dependency Parsing.md)
      • [Lecture 06 The Probability Of A Sentence Recurrent Neural Networks And Language Models](CourseNote/cs224n2019/Lecture 06 The probability of a sentence Recurrent Neural Networks and Language Models.md)
      • Stanford NLP
    • Deep Learning Book Goodfellow
      • Books
        • Deep Learning Book Chapter Summaries Master
      • 提纲
      • C 5
      • C 6
      • [Part I Applied Math And Machine Learning Basics](CourseNote/Deep-Learning-Book-Goodfellow/Part I - Applied Math and Machine Learning basics.md)
    • Lihang
    • NLP实战高手课
      • 极客时间_NLP实战高手课
    • 工具&资料
    • 机器学习、深度学习面试知识点汇总
    • 七月kaggle课程
    • 算法工程师
    • 贪心科技机器学习必修知识点特训营
    • 唐宇迪机器学习
    • 语言及工具
    • AI技术内参
    • Suggestions
  • Data Related
    • 数据质量
      • 置信学习
    • 自然语言处理中的数据增广_车万翔
      • 自然语言处理中的数据增广
    • Mixup
    • 数据不均衡问题
    • 数据增强的方法
  • Knowledge Graph
    • Information Extraction
      • 联合抽取
        • PRGC
      • Code
        • BERT微调
      • NER
        • 阅读理解做NER
          • MRC
        • FLAT
        • Global Pointer
        • 命名实体识别NER
    • Keyword Extraction
      • 关键词抽取
    • 小米在知识表示学习的探索与实践
    • KG
  • Multi Task
    • EXT 5
      • Ex T 5
  • NLG
    • Dailogue
      • 比赛
        • 对话评估比赛
          • [simpread-DSTC10 开放领域对话评估比赛冠军方法总结](NLG/Dailogue/比赛/对话评估比赛/simpread-DSTC10 开放领域对话评估比赛冠军方法总结.md)
      • 任务型对话
        • DST
          • DST概述
        • NLG
          • NLG概述
        • NLU
          • NLU概述
        • 任务型对话概述
        • simpread-任务型对话系统预训练最新研究进展
      • 问答型对话
        • 检索式问答
          • 基于预训练模型的检索式对话系统
          • 检索式文本问答
        • 业界分享
          • 低资源场景下的知识图谱表示学习和问答_阿里_李杨
          • QQ浏览器搜索智能问答
        • 问答型对话系统概述
      • 闲聊型对话
        • 闲聊型对话系统概述
      • 业界分享
        • 人工智能与心理咨询
        • 腾讯多轮对话机器人
        • 微软小冰
        • 小布助手闲聊生成式算法
        • 美团智能客服实践_江会星
        • 去哪儿智能客服探索和实践
        • 实时语音对话场景下的算法实践_阿里_陈克寒
        • 智能语音交互中的无效query识别_小米_崔世起
        • UNIT智能对话
      • 主动对话
      • EVA
        • EVA分享
        • EVA模型
      • PLATO
      • RASA
    • Machine Translation
      • 业界分享
        • 爱奇艺台词翻译分享
      • Paper
        • Deep Encoder Shallow Decoder
    • RAGRelated
    • Text 2 SQL
      • M SQL
        • [M SQL 2](NLG/Text2SQL/M-SQL/M-SQL (2).md)
      • [Text2SQL Baseline解析](NLG/Text2SQL/Text2SQL Baseline解析.md)
      • Text 2 SQL
    • Text Summarization
      • [文本摘要][paper]CTRLSUM
      • 文本摘要
  • Pre Training
    • 业界分享
      • 超大语言模型与语言理解_黄民烈
        • 超大语言模型与语言理解
      • 大模型的加速算法_腾讯微信
        • 大模型的加速算法
      • 孟子轻量化预训练模型
      • 悟道文汇文图生成模型
      • 悟道文澜图文多模态大模型
      • 语义驱动可视化内容创造_微软
        • 语义驱动可视化内容创造
    • Base
      • Attention
      • Mask
        • NLP中的Mask
      • Position Encoding
        • 位置编码
    • BERT
      • ALBERT
      • Bert
        • Venv
          • Lib
            • Site Packages
              • idna-3.2.dist-info
                • LICENSE
              • Markdown-3.3.4.dist-info
                • LICENSE
              • Tensorflow
                • Include
                  • External
                    • Libjpeg Turbo
                      • LICENSE
                  • Unsupported
                    • Eigen
                      • CXX 11
                        • Src
                          • Tensor
              • Werkzeug
                • Debug
                  • Shared
                    • ICON LICENSE
        • CONTRIBUTING
        • Multilingual
      • Ro BER Ta
      • BERT
      • BERT面试问答
      • BERT源码解析
      • NSP BERT
    • BERT Flow
    • BERT Zip
      • Distilling The Knowledge In A Neural Network
      • TINYBERT
      • 模型压缩
    • CPM
    • CPT
      • 兼顾理解和生成的中文预训练模型CPT
    • ELECTRA
    • EL Mo
    • ERNIE系列语言模型
    • GPT
    • MBART
    • NEZHA
    • NLG Sum
      • [simpread-预训练时代下的文本生成|模型 & 技巧](Pre-training/NLGSum/simpread-预训练时代下的文本生成|模型 & 技巧.md)
    • Prompt
      • 预训练模型的提示学习方法_刘知远
        • 预训练模型的提示学习方法
    • T 5
      • Unified SKG
      • T 5
    • Transformer
    • Uni LM
    • XL Net
    • 预训练语言模型
    • BERT变种
  • Recsys
    • 多任务Multi-task&推荐
    • 推荐介绍
    • 推荐系统之召回与精排
      • 代码
        • Python
          • Recall
            • Deep Match Master
              • Docs
                • Source
                  • Examples
                  • FAQ
                  • Features
                  • History
                  • Model Methods
                  • Quick Start
    • 业界分享
      • 腾讯基于知识图谱长视频推荐
    • 召回
    • Sparrow Rec Sys
    • 深度学习推荐系统实战
    • 推荐模型
    • Deep FM
  • Search
    • 搜索
    • 业界分享
      • 爱奇艺搜索排序算法实践
      • 语义搜索技术和应用
    • 查询关键字理解
    • 搜索排序
    • BM 25
    • KDD21-淘宝搜索中语义向量检索技术
    • query理解
    • TFIDF
  • Self Supervised Learning
    • Contrastive Learning
      • 业界分享
        • 对比学习在微博内容表示的应用_张俊林
      • Paper
      • R Drop
      • Sim CSE
    • 自监督学习
  • Text Classification
    • [多标签分类(Multi-label Classification)](TextClassification/多标签分类(Multi-label Classification)/多标签分类(Multi-label Classification).md)
    • Fast Text
    • Text CNN
    • 文本分类
  • Text Matching
    • 文本匹配和多轮检索
    • CNN SIM
    • Word Embedding
      • Skip Gram
      • Glove
      • Word 2 Vec
    • 文本匹配概述
  • Tool
    • 埋点
    • 向量检索(Faiss等)
    • Bigdata
      • 大数据基础task1_创建虚拟机+熟悉linux
      • 任务链接
      • Mr
      • Task1参考答案
      • Task2参考答案
      • Task3参考答案
      • Task4参考答案
      • Task5参考答案
    • Docker
    • Elasticsearch
    • Keras
    • Numpy
    • Python
      • 可视化
        • Interactivegraphics
        • Matplotlib
        • Tkinter
        • Turtle
      • 数据类型
        • Datatype
      • python爬虫
        • Python Scraping Master
          • phantomjs-2.1.1-windows
        • Regularexp
        • Scrapying
        • Selenium
      • 代码优化
      • 一行代码
      • 用python进行语言检测
      • Debug
      • Exception
      • [Features Tricks](Tool/python/Features & Tricks.md)
      • Fileprocess
      • Format
      • Functional Programming
      • I Python
      • Magic
      • Math
      • Os
      • Others
      • Pandas
      • Python Datastructure
      • Python操作数据库
      • Streamlit
      • Time
    • Pytorch
      • Dive Into DL Py Torch
        • 02 Softmax And Classification
        • 03 Mlp
        • 04 Underfit Overfit
        • 05 Gradient Vanishing Exploding
        • 06 Text Preprocess
        • 07 Language Model
        • 08 Rnn Basics
        • 09 Machine Translation
        • 10 Attention Seq 2 Seq
        • 11 Transformer
        • 12 Cnn
        • 14 Batchnorm Resnet
        • 15 Convexoptim
        • 16 Gradientdescent
        • 17 Optim Advance
    • Spark
      • Pyspark
        • pyspark之填充缺失的时间数据
      • Spark
    • SQL
      • 数据库
      • Hive Sql
      • MySQL实战45讲
    • Tensor Flow
      • TensorFlow入门
  • Common
  • NLP知识体系
Powered by GitBook
On this page
  • Matplotlib库小测
  • pyplot的绘图区域
  • pyplot的plot()函数
  • pyplot的中文显示:第一种方法
  • pyplot的中文显示:第二种方法
  • pyplot的文本显示
  • pyplot的子绘图区域
  • pyplot基础图标函数概述
  • pyplot饼图的绘制
  • pyploy直方图的绘制
  • pyplot极坐标图的绘制
  • pyplot散点图的绘制

Was this helpful?

  1. Tool
  2. Python
  3. 可视化

Matplotlib

Matplotlib库小测

plt.plot()只有一个输入列表或数组时,参数被当作Y轴,X轴以索引自动生成 plt.plot(x,y)当有两个以上参数时,按照X轴和Y轴顺序绘制数据点 plt.savefig()将输出图形存储为文件,默认PNG格式,可以通过dpi修改输出质量

pyplot的绘图区域

plt.subplot(nrows, ncols, plot_number) plt.subplot(3,2,4)或plt.subplot(324) 在全局绘图区域中创建一个分区体系,并定位到一个绘图区域

pyplot的plot()函数

plt.plot(x, y, format_string, **kwargs) ∙ x : X轴数据,列表或数组,可选 ∙ y : Y轴数据,列表或数组 ∙ format_string: 控制曲线的格式字符串,可选 ∙ **kwargs : 第二组或更多(x,y,format_string) 当绘制多条曲线时,各条曲线的x不能省略 format_string: 控制曲线的格式字符串,可选 由颜色字符、风格字符和标记字符组成

'b' 蓝色 'm' 洋红色magenta 'g' 绿色 'y' 黄色 'r' 红色 'k' 黑色 'c' 青绿色cyan 'w' 白色 '#008000' RGB某颜色 '0.8' 灰度值字符串

风格字符 '‐' 实线 '‐‐' 破折线 '‐.' 点划线 ':' 虚线 '' ' ' 无线条

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

**kwargs : 第二组或更多(x,y,format_string) color : 控制颜色, color='green' linestyle : 线条风格, linestyle='dashed' marker : 标记风格, marker='o' markerfacecolor: 标记颜色,markerfacecolor='blue' markersize : 标记尺寸, markersize=20 ……

a = np.arange(10)
plt.plot(a, a*1.5, a,a*2.5,a,a*3.5,a,a*4.5)
plt.show()
plt.plot(a,a*1.5,'go-',a,a*2.5,'rx',a,a*3.5,'*',a,a*4.5,'b-.')
plt.show()

pyplot的中文显示:第一种方法

pyplot并不默认支持中文显示,需要rcParams修改字体实现 matplotlib.rcParams['font.family']='SimHei'

rcParams的属性 'font.family' 用于显示字体的名字 'font.style' 字体风格,正常'normal'或斜体'italic' 'font.size' 字体大小,整数字号或者'large'、'x‐small'

中文字体的种类rcParams['font.family'] 'SimHei' 中文黑体 'Kaiti' 中文楷体 'LiSu' 中文隶书 'FangSong' 中文仿宋 'YouYuan' 中文幼圆 'STSong' 华文宋体

pyplot的中文显示:第二种方法

在有中文输出的地方,增加一个属性:fontproperties plt.xlabel('横轴:时间',fontproperties='SimHei',fontsize=20)

pyplot的文本显示

plt.xlabel() 对X轴增加文本标签 plt.ylabel() 对Y轴增加文本标签 plt.title() 对图形整体增加文本标签 plt.text() 在任意位置增加文本 plt.annotate() 在图形中增加带箭头的注解 plt.annotate(s, xy=arrow_crd, xytext=text_crd, arrowprops=dict)

a = np.arange(0.0,5.0,0.02)
plt.plot(a, np.cos(2*np.pi*a), 'r--')
plt.xlabel('横轴:时间',fontproperties='SimHei',fontsize=25,color='green')
plt.xlabel('纵轴:振幅',fontproperties='SimHei',fontsize=25)
plt.title(r'正弦波实例 $y=cos(2\pi x)$',fontproperties='SimHei',fontsize=25)
plt.annotate(r'$\mu=100$',xy=(2,1),xytext=(3,1.5),arrowprops=dict(facecolor='black',shrink=0.1,width=1))
plt.axis([-1,6,-2,2])
plt.grid(True)
plt.show()

pyplot的子绘图区域

plt.subplot2grid(GridSpec, CurSpec, colspan=1, rowspan=1) 理念:设定网格,选中网格,确定选中行列区域数量,编号从0开始 plt.subplot2grid((3,3), (1,0), colspan=2)

GridSpec类

import matplotlib.gridspec as gridspec
gs = gridspec.GridSpec(3,3)
ax1 = plt.subplot(gs[0, :])
ax2 = plt.subplot(gs[1, :-1])
ax3 = plt.subplot(gs[1:, -1])
ax4 = plt.subplot(gs[2, 0])
ax5 = plt.subplot(gs[2, 1])

pyplot基础图标函数概述

plt.plot(x,y,fmt,…) 绘制一个坐标图 plt.boxplot(data,notch,position) 绘制一个箱形图 plt.bar(left,height,width,bottom) 绘制一个条形图 plt.barh(width,bottom,left,height) 绘制一个横向条形图 plt.polar(theta, r) 绘制极坐标图 plt.pie(data, explode) 绘制饼图 plt.psd(x,NFFT=256,pad_to,Fs) 绘制功率谱密度图 plt.specgram(x,NFFT=256,pad_to,F) 绘制谱图 plt.cohere(x,y,NFFT=256,Fs) 绘制X‐Y的相关性函数 plt.scatter(x,y) 绘制散点图,其中,x和y长度相同 plt.step(x,y,where) 绘制步阶图 plt.hist(x,bins,normed) 绘制直方图 plt.contour(X,Y,Z,N) 绘制等值图 plt.vlines() 绘制垂直图 plt.stem(x,y,linefmt,markerfmt) 绘制柴火图 plt.plot_date() 绘制数据日期

pyplot饼图的绘制

import matplotlib as plt
labels = 'Frogs','Hogs','Dogs','Logs'
sizes = [15,30,45,10]
explode = (0,0.1,0,0)
plt.pie(sizes,explode=explode,labels=labels,autopct='%1.1f%%',shadow=False,startangle=90)
# plt.axis('equal')
plt.show()

pyploy直方图的绘制

import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
mu,sigma = 100,20  # 均值,标准差
a = np.random.normal(mu, sigma, size=100)

plt.hist(a,20,normed=1,histtype='stepfilled',facecolor='b',alpha=0.75)
# 20 bin:直方图的个数
plt.title('Histogram')
plt.show()

pyplot极坐标图的绘制

面向对象绘制极坐标

import numpy as np
import matplotlib.pyplot as plt

N = 20
theta = np.linspace(0.0,2*np.pi,N,endpoint=False)
radii = 10*np.random.rand(N)
width = np.pi / 4*np.random.rand(N)
# width = np.pi / 4*np.random.rand(N)

ax = plt.subplot(111,projection='polar')
bars = ax.bar(theta,radii,width=width,bottom=0.0)
# ax.bar(left,height,width)

for r,bar in zip(radii,bars):
    bar.set_facecolor(plt.cm.viridis(r / 10.))
    bar.set_alpha(0.5)

plt.show()

pyplot散点图的绘制

面向对象绘制散点图

import numpy as np
import matplotlib.pyplot as plt

fig,ax = plt.subplots()
ax.plot(10*np.random.randn(100),10*np.random.randn(100), 'o')
ax.set_title('Simple Scatter')

plt.show()
PreviousInteractivegraphicsNextTkinter

Last updated 2 years ago

Was this helpful?