• python绘图系统27:matplotlib中平面坐标、极坐标和三维坐标的所有绘图函数


    绘图函数列表

    下面整理了几乎所有matplotlib中的绘图函数,及其在不同坐标轴下的表现。

    函数类别2Dpolar3D备注
    imshow图像X
    pcolormesh伪彩图[X,Y,]ZX,Y,Z
    plot曲线图x[,y]x[,y]x,y[,z]
    scatter散点图x,y/X,Yx,yx,y,[,z]可为任意维度
    stem茎叶图x,yx,yx,y[,z]
    step阶梯图x,yx,yx,y[,z]
    bar条形图x,yx,yx,y[,z]
    barh横向条形图x,yx,y
    stackplot填充线图x,yx,y
    plot_surface曲面图x,y,zx,y必须是网格
    plot_wireframe网格图x,y,zx,y必须是网格
    plot_trisurf三角面图x,y,zx,y,z是一维数组
    errorbar误差线x,y
    xerr,yerr
    x,y
    xerr,yerr
    x,y,z
    xerr,yerr,zerr
    fill_between纵向区间图x,y1,y2x,y1,y2
    fill_betweenx横向区间图y, x1, x2x,y1,y2
    contour等高线[x,y,]z[x,y,]zx,y,z
    contourf填充等高线[x,y,]z[x,y,]zx,y,z
    quiver向量场图x,y,u,vx,y,u,vx,y,z,u,v,w
    streamplot流场图x,y,u,vx,y,u,v
    barbs风场图x,y,u,vx,y,u,v
    hist直方图xxx
    boxplot箱线图xxx
    violinplot小提琴图xx
    enventplot信封图xx
    hist2d二维直方图x,yx,y
    hexbin钻石图x,yx,y
    pie饼图xx
    tricontour自由等高线x,y,zx,y,zx,y,z
    tricontourf自由填充等高线x,y,zx,y,zx,y,z
    tricolor自由伪彩图x,y,z
    triplot三角骨架图x,y

    为DrawType添加这些绘图函数

    之所以闲得无聊总结matplotlib中的绘图函数,是为了在Python绘图系统中正确第调用它们。

    有了这些绘图类别后,首先绘图字典需要更新,这个字典不能做成全局变量,因为其中的ax,其实是作为函数参数传递进来的。

    funcDct = {
        "点线图"  : ax.plot,    "曲线图" : ax.plot, 
        "散点图"  : ax.scatter, 
        "图像"    : ax.imshow,  "伪彩图" : ax.pcolormesh, 
        "条形图"  : ax.bar,     "横向条形图": ax.barh, 
        "茎叶图"  : ax.stem,    "阶梯图": ax.step,
        "填充图"  : ax.stackplot, 
        "误差线"  : ax.errorbar, 
        "区间图"  : ax.fill_between, "横向区间图": ax.fill_betweenx, 
        "曲面图"  : ax.plot_surface, 
        "网格图"  : ax.plot_wireframe,
        "三角面图": ax.plot_trisurf,
        "等高线"  : ax.contour, "填充等高线" : ax.contourf,
        "向量场图": ax.quiver,  "流场图":ax.streamplot,
        "风场图"  : ax.barbs, 
        "直方图"  : ax.hist,    "二维直方图":ax.hist2d,
        "钻石图"  : ax.hexbin,  "信封图"  : ax.enventplot, 
        "箱线图"  : ax.boxplot, "小提琴图":violinplot,
        "饼图"    : ax.pie,
        "自由等高线" : ax.tricontour,
        "自由填充等高线" : ax.tricontourf,
        "自由伪彩图" : ax.tricolor,
        "三角骨架图" : ax.triplot
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    然后据此更新self.TYPES,

    self.TYPES = [
        "点线图", "曲线图", "散点图", "图像", "伪彩图" , 
        "条形图", "横向条形图", "茎叶图", "阶梯图", "填充图", 
        "误差线", "区间图", "横向区间图",  "曲面图",  
        "网格图", "三角面图", "等高线",  "填充等高线",
        "向量场图", "流场图", "风场图",  "直方图", "二维直方图", 
        "钻石图", "信封图", "箱线图", "小提琴图", "饼图", 
        "自由等高线", "自由填充等高线" ,"自由伪彩图" ,"三角骨架图"]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    绘图类别跳转坐标系

    这些绘图函数建议使用的坐标系如下表

    绘图函数图像类别建议的坐标
    imshow图像None
    plot_surface曲面图3d
    plot_wireframe网格图3d
    plot_trisurf三角面图3d
    tricontour自由等高线None, polar, 3d
    plot曲线图None, polar, 3d
    scatter散点图None, polar, 3d
    stem茎叶图None, polar, 3d
    step阶梯图None, polar, 3d
    bar条形图None, polar, 3d
    errorbar误差线None, polar, 3d
    contour等高线None, polar, 3d
    quiver向量场图None, polar, 3d
    pcolormesh伪彩图None, polar
    barh横向条形图None, polar
    stackplot填充线图None, polar
    fill_between区间图None, polar,
    fill_betweenx横向区间图None, polar,
    streamplot流场图None, polar
    barbs风场图None, polar
    violinplot小提琴图None, polar
    enventplot信封图None, polar
    hist2d二维直方图None, polar
    hexbin钻石图None, polar
    pie饼图None, polar
    tricolor自由伪彩图None, polar
    triplot三角骨架图None, polar
    contourf填充等高线None, polar
    tricontourf自由填充等高线None, polar
    hist直方图None, polar
    boxplot箱线图None, polar
    tricontour自由等高线None, polar, 3d
    plot曲线图None, polar, 3d
    scatter散点图None, polar, 3d
    stem茎叶图None, polar, 3d
    step阶梯图None, polar, 3d
    bar条形图None, polar, 3d
    errorbar误差线None, polar, 3d
    contour等高线None, polar, 3d
    quiver向量场图None, polar, 3d

    故更改cbTypeChanged函数如下

    def cbTypeChanged(self, evt):
        t = self.drawVars['type'].get()
        p = self.drawVars['proj'].get()
        NO3D = ("曲线图", "散点图", "茎叶图", "条形图", "误差线",
            "等高线", "向量场图", "自由等高线")
        if t in ("图像"):
            self.wDct['proj']['value'] =  ("None")
        elif t in ("曲面图", "网格图", "三角面图"):
            self.wDct['proj']['value'] =  ("3d")
        elif t in NO3D:
            self.wDct['proj']['value'] =  ("None", "3d", "polar")
        else:
            self.wDct['proj']['value'] =  ("None", "polar")
        
        projs = self.wDct['proj']['value']
        if p not in projs:
            self.drawVars['proj'].set(projs[0])        
        self.cbProjChanged(None)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    坐标

    接下来要为这些绘图函数分类,发现最特殊的是imshow,只支持平面直角坐标;然后是三个三维绘图函数,只支持三维直角坐标,剩下的基本都同时支持平面直角和极坐标。

    def cbTypeChanged(self, evt):
        t = self.drawVars['type'].get()
        p = self.drawVars['proj'].get()
        NO3D = ("曲线图", "散点图", "茎叶图", "条形图", "误差线",
            "等高线", "向量场图", "自由等高线")
        if t in ("图像"):
            self.wDct['proj']['value'] =  ("None")
        elif t in ("曲面图", "网格图", "三角面图"):
            self.wDct['proj']['value'] =  ("3d")
        elif t in NO3D:
            self.wDct['proj']['value'] =  ("None", "3d", "polar")
        else:
            self.wDct['proj']['value'] =  ("None", "polar")
        
        projs = self.wDct['proj']['value']
        if p not in projs:
            self.drawVars['proj'].set(projs[0])        
        self.cbProjChanged(None)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    最后,是坐标的变化,直角坐标系下的变化为

    def cbProjNone(self, t):
        if t in ("点线图", "曲线图"):
            self.wDct['dim']['value'] = ('x', 'xy')
        elif t in ("图像", "直方图", "饼图", "箱线图", "小提琴图", "信封图"):
            self.wDct['dim']['value'] = ('x')
        elif t in ("误差线", "向量场图", "流场图", "风场图"):
            self.wDct['dim']['value'] = ('xyuv')
        elif t in ("伪彩图", "等高线", "填充等高线"):
            self.wDct['dim']['value'] = ('x', 'xyz')
        elif t in ("区间图", "横向区间图", "自由等高线", "自由伪彩图", "自由填充等高线"):
            self.wDct['dim']['value'] = ('xyz')
        else:
            self.wDct['dim']['value'] = ('xy')
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    经过对比发现,极坐标情况下除了没有imshow之外,其他绘图函数的坐标轴的个数与直角坐标基本相同,所以就直接调用cbProjNone了。

    def cbProjPolar(self, t):
        self.cbProjNone(t)
    
    • 1
    • 2

    相比之下,三维坐标的情况可能更加简单一些

    def cbProj3d(self, t):
        if t  in ("向量场图", "误差线"):
            self.wDct['dim']['value'] = ('xyzuvw')
        elif t in ("曲线图", "散点图", "茎叶图", "阶梯图", "条形图"):
            self.wDct['dim']['value'] = ('xy', 'xyz')
        else:
            self.wDct['dim']['value'] = ('xyz')
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    至此,就成功载入了几乎所有matplotlib中的函数。

    源代码

    Python绘图系统:

  • 相关阅读:
    L18.linux命令每日一练 -- 第三章 文件过滤及内容编辑处理命令 -- head和tail命令
    如何衡量CRM投资回报率?CRM系统如何提升投资回报率?
    【Luogu】UVA1205 Color a Tree / SP3912 MTREECOL - Color a tree
    详解CAN总线:高速CAN总线和低速CAN总线的特性
    云原生|kubernetes|etcd集群详细介绍+安装部署+调优
    Vue中如何进行自定义图表与可视化图形设计
    智慧城市-疫情流调系列2.1-Prompt-UIE信息抽取,解决抽取结果不准的问题
    kotlin 音频播放,多音轨同时播放,音频播放期间,可以随时设置播放速度
    方法引用知识点
    SSM框架学习——MyBatis Plus
  • 原文地址:https://blog.csdn.net/m0_37816922/article/details/132290278