Matplotlib

matplotlib: 最流行的Python底层绘图库,主要做数据可视化图表,名字取材于MATLAB,模仿MATLAB构建

绘制折线图

绘制两小时的温度变化

from matplotlib import pyplot as plt

x = range(2, 26, 2)
y = [15, 13, 14, 5, 17, 20, 25, 26, 24, 22, 19, 15]
# 全局变量fig figure方法(figsize画板尺寸=(长float,宽float), dpi=整数int)
fig = plt.figure(figsize=(20, 8), dpi=80)
# 传入X坐标和Y坐标,并绘图
plt.plot(x, y)
# 调整X轴刻度,传入的列表密集与否,决定X轴的密集程度
plt.xticks(x)
# 调整X轴刻度同理
plt.yticks(range(min(y), max(y)+1))
# savefig方法,传入一个路径
plt.savefig("./t1.png")
# 展示
plt.show()

from matplotlib import pyplot as plt
import random
from matplotlib import font_manager x = range(0, 120)
y = [random.randint(20, 35) for i in range(120)] # C:\Windows\Fonts\simhei.ttf 字体路径
# 实例化font_manager
my_font = font_manager.FontProperties(fname="C:\Windows\Fonts\simhei.ttf")
plt.figure(figsize=(20, 8), dpi=80) plt.plot(x, y) # 调整x轴的刻度
_xtick_labels = ["10点{}分".format(i) for i in range(60)]
_xtick_labels += ["11点{}分".format(i) for i in range(60)] # 取步长,数字和字符串一一对应,数据的长度与数据的刻度一笔一致
# param: rotation=旋转角度(int)
# param: fontproperties=实例化的字体(object)
plt.xticks(list(x)[::3], _xtick_labels[::3],
rotation=45, fontproperties=my_font)
# 添加描述信息
plt.xlabel("时间", fontproperties=my_font) # X轴标签
plt.ylabel("温度 ℃", fontproperties=my_font) # Y轴标签
plt.title("10点到12点每分钟的气温变化情况", fontproperties=my_font) # 标题 plt.show()

模拟11岁到30岁自己和同桌交女朋友的走势

# coding=utf-8
from matplotlib import pyplot as plt
from matplotlib import font_manager my_font = font_manager.FontProperties(fname="C:\Windows\Fonts\simhei.ttf") y_1 = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1]
y_2 = [1, 0, 3, 1, 2, 2, 3, 3, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1] x = range(11, 31) # 设置图形大小
plt.figure(figsize=(20, 8), dpi=80) plt.plot(x, y_1, label="自己", color="red")
plt.plot(x, y_2, label="同桌", color="#DB7093", linestyle="--") # 设置x轴刻度
_xtick_labels = ["{}岁".format(i) for i in x]
plt.xticks(x, _xtick_labels, fontproperties=my_font)
# plt.yticks(range(0,9)) # 绘制网格
plt.grid(alpha=0.4, linestyle=':') # 添加图例
plt.legend(prop=my_font, loc="upper left") # 展示
plt.show()

绘制折线图总结

Matplotlib 绘制折线图的更多相关文章

  1. python使用matplotlib绘制折线图教程

    Matplotlib是一个Python工具箱,用于科学计算的数据可视化.借助它,Python可以绘制如Matlab和Octave多种多样的数据图形.下面这篇文章主要介绍了python使用matplot ...

  2. Python开发【模块】:matplotlib 绘制折线图

    matplotlib 1.安装matplotlib ① linux系统安装 # 安装matplotlib模块 $ sudo apt-get install python3-matplotlib # 如 ...

  3. 【Python】matplotlib绘制折线图

    一.绘制简单的折线图 import matplotlib.pyplot as plt squares=[1,4,9,16,25] plt.plot(squares) plt.show() 我们首先导入 ...

  4. 1 matplotlib绘制折线图

    from matplotlib import pyplot as plt #设置图形大小 plt.figure(figsize=(20,8),dpi=80) plt.plot(x,y,color=&q ...

  5. matplotlib之折线图

    1.案例一 # coding=utf-8 from matplotlib import pyplot as plt import random # 设置字体相关 from matplotlib imp ...

  6. Python绘制折线图

    一.Python绘制折线图 1.1.Python绘制折线图对应代码如下图所示 import matplotlib.pyplot as pltimport numpy as np from pylab ...

  7. 用canvas绘制折线图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. php中用GD绘制折线图

    php中用GD绘制折线图,代码如下: Class Chart{ private $image; // 定义图像 private $title; // 定义标题 private $ydata; // 定 ...

  9. python中matplotlib画折线图实例(坐标轴数字、字符串混搭及标题中文显示)

    最近在用python中的matplotlib画折线图,遇到了坐标轴 "数字+刻度" 混合显示.标题中文显示.批量处理等诸多问题.通过学习解决了,来记录下.如有错误或不足之处,望请指 ...

  10. UUChart的使用--iOS绘制折线图

    UUChart是一个用于绘制图表的第三方,尤其适合去绘制折线图. 二.下载地址: https://github.com/ZhipingYang/UUChartView 三.使用 第一步.首先我们将下载 ...

随机推荐

  1. 齐博x1模板中常用的TP标签数据处理

    上图是比较常用的, 而下图是比较特殊的场合,比如幻灯片可能会用到 下图使用了TP的循环标签. 上图只使用了条件判断标签 上图不存在 val="xxx" 这个参数,所以会自动循环输出 ...

  2. 齐博x1页面不直接报错,如何排查

    有的页面是不会直接报错的,比如像下面这个,这个时候需要你用谷歌或火狐浏览器打开,按F12键进入开发者模式,然后选择Network选项,刷新一下当前的网页,就会看到红色的请求.单独打开他.就可以看到错误 ...

  3. CJK备注

    pip清华镜像库 :pip install XXX -i https://pypi.tuna.tsinghua.edu.cn/simple pip阿里巴巴镜像库:pip install XXX -i ...

  4. JS逆向实战7-- 某省在线审批网站params 随机生成

    参数分析 我们首先通过抓包 发现这个就是我们所需要的数据 然后我们通过fidder 发起请求 结果: 通过我们反复测试 发现这个params的参数是每次请求中都会变化的 断点查找 我们通过 这个t参数 ...

  5. pod(九):污点taint 与容忍度tolerations

    目录 一.系统环境 二.前言 三.污点taint 3.1 污点taint概览 3.2 给节点添加污点taint 四.容忍度tolerations 4.1 容忍度tolerations概览 4.2 设置 ...

  6. Git创建、diff代码、回退版本、撤回代码,学废了吗

    .eye-care { background-color: rgba(199, 237, 204, 1); padding: 10px } .head-box { display: flex } .t ...

  7. C#使用GDI+同时绘制图像和ROI在picturebox上

    Bitmap bmp; /// <summary> /// 绘制图像 /// </summary> /// <param name="g">Gr ...

  8. Go语言核心36讲04

    我们已经知道,环境变量GOPATH指向的是一个或多个工作区,每个工作区中都会有以代码包为基本组织形式的源码文件. 这里的源码文件又分为三种,即:命令源码文件.库源码文件和测试源码文件,它们都有着不同的 ...

  9. 面试官不按套路,竟然问我Java线程池是怎么统计线程空闲时间?

    背景介绍: 你刚从学校毕业后,到新公司实习,试用期又被毕业,然后你又不得不出来面试,好在面试的时候碰到个美女面试官! 面试官: 小伙子,我看你简历上写的项目中用到了线程池,你知道线程池是怎样实现复用线 ...

  10. 读Bilgin Ibryam 新作 《Dapr 是一种10倍数 平台》

    Bilgin Ibryam 最近加入了开发者软件初创公司Diagrid Inc,他是Apache Software Foundation 的 committer 和成员.他也是一个开源的布道师,并且是 ...