matplotlib从零开始之一(等级制度认知)
matplotlib的等级制度
最近看的python机器学习的书里面经常提到用matplotlib将数据可视化,都是从这样的格式开始的:
fig, ax = plt.subplots() ax.plot(A,B) ax.axis... ax.add_artist(...)
什么是figure,axes, axis,artist呢?
官方文档提到了hierarchy
At the top of the hierarchy is the matplotlib “state-machine environment” which is provided by the
matplotlib.pyplotmodule.At this level, simple functions are used to add plot elements (lines, images, text, etc.) to the current axes in the current figure.
The next level down in the hierarchy is the first level of the object-oriented interface, in which pyplot is used only for a few functions such as figure creation, and the user explicitly creates and keeps track of the figure and axes objects. At this level, the user uses pyplot to create figures, and through those figures, one or more axes objects can be created. These axes objects are then used for most plotting actions.
官方图片是这样画的:
官方解释: matplotlib.
pyplot模块创建figure,figure控制所有的Axes,一些特殊的artist和canvas。
大概看了一下,不是能够全部理解。
小小的总结一下基础的method和处理的对象,日后再以此为基础进行补充。
需要注意的是artist的概念更加广泛,基本上所能见到的都是artist,Figure、Axes、Axis等都是,只不过一些artist属于某一个axes,如果一个Figure有很多个Axes的话,它们各自的artist是不共享的。当artist被创建以后,存在canvas里。
建议的用法
fig = plt.figure() # an empty figure with no axes fig, ax_lst = plt.subplots(2, 2) # a figure with a 2x2 grid of Axes
先学了这些,其他的还没有尝试,遇到具体的问题的时候再仔细处理吧,正确认识matplotlib的等级结构,才不至于总是做出dirty plot。这也是当初学习R语言的ggplot2的一些经验。因为认识不到位,总是通过Google来进行修改,效率很低。
不知道是不是因为刚刚学习,对matplotlib还不了解,总感觉ggplot2用起来的时候更加简洁。再学习看看吧。python机器学习的书要看懂的话,还是不要被可视化的部分影响效率。
- 点赞
- 收藏
- 分享
- 文章举报
- 从零开始学习Matplotlib(二)
- 从零开始学Python数据分析【12】-- matplotlib(箱线图)
- 从零开始机器学习实战2-Matplotlib绘图
- 从零开始学Python数据分析【11】-- matplotlib(饼图)
- (Datacamp)从零开始学python(3)——Matplotlib
- 从零开始学习Matplotlib(一)
- 从零开始学习Matplotlib(三)
- ubuntu 安装numpy和matplotlib
- 【python笔记】使用matplotlib,pylab进行python绘图
- import matplotlib出错
- [完]Python,解决Matplotlib制图时的中文问题
- matplotlib.pyplot画图 图片的二进制流的获取方法
- python matplotlib绘图,修改坐标轴刻度为文字的实例
- python中matplotlib图例中文显示问题/信号处理/中值滤波
- Python/Matplotlib实现雨点图动画
- numpy、scipy、matplotlib基础介绍
- numpy、scipy、pandas、matplotlib了解
- matplotlib绘图,图标注释(2)
- Win 7/10安装numpy、pandas、scipy和matplotlib
- matplotlib绘图及pandas数据分析小总结