matplotlib学习总结

1 篇文章 0 订阅
1 篇文章 0 订阅

经典matplotlib图

  • 学习matplotlib画图已经有一段时间了,各种操作都做了一遍,但是还是有点迷糊,尤其是坐标轴上各个部分的名称,在此特意将matplotlib上的经典例图的各部分名称全部总结在此,做个总结,以后再做操作上补充。

主要图像要素的名称

  • Title
    • 图名(在整个图的上面)
  • label
    • 标签(在坐标轴的边上)
    • 应用
      • 坐标轴标签自适应
        • fig.autofmt_xdate()
      • 设置y轴标签
        • ax1.set_ylabel(‘Y1’)
  • tick
    • 刻度
    • 设置坐标轴有多少格
      • ax.locator_params(‘x’, nbins = 10) # 设置x轴有10格组成
  • legend
    • 图例
    • 应用
      • plt.legend(loc = 0, ncol = 3) # 0代表最佳位置,3表示有三列
      • ax.legend()
  • grid
    • 背景网格
    • 应用
      • plt.grid(True)
      • ax.grid(True)
  • text
    • 文字注释(可以用TeX公式)
    • 应用
      • plt.text()
      • ax.text(2,4,r"$ \alpha_i \beta_j \pi \lambda \omega $", size = 25)
  • axis
    • 坐标轴
    • xmin, xmax, ymin, ymax = axis()
    • xmin, xmax, ymin, ymax = axis([xmin, xmax, ymin, ymax])
    • xmin, xmax, ymin, ymax = axis(option)
    • xmin, xmax, ymin, ymax = axis(**kwargs)
    • 参数可以为下列单词

============================================================

ValueDescription
‘on’Turn on axis lines and labels. Same as True.
‘off’Turn off axis lines and labels. Same as False.
‘equal’Set equal scaling (i.e., make circles circular) bychanging axis limits.
‘scaled’Set equal scaling (i.e., make circles circular) by changing dimensions of the plot box.
‘tight’Set limits just large enough to show all data.
‘auto’Automatic scaling (fill plot box with data).
‘normal’Same as ‘auto’; deprecated.
‘image’‘scaled’ with axis limits equal to data limits.
‘square’Square plot; similar to ‘scaled’, but initially forcing xmax-xmin = ymax-ymin

===========================================================

  • 应用

    • 可以自己定制坐标范围
      • plt.axis([-100,100,-10,200])
    • 单独调节某个参数
      • plt.xlim([-5,5])
    • 添加坐标轴
      • plt.twinx()
  • figure

    • 画板,是画纸的载体
    • https://www.zhihu.com/question/51745620

  • Axes/Subplot

    • 画纸 轴域 ~=子图

    • axes(轴域)可以理解一些轴的集合:axes不是数学上的座标轴,而是图形结构中的一个对象。所有绘图函数都是直接作用在当前axes对象上。

    • subplot子图就是画板上的画纸

    • 应用

      • plt.subplot(221)
      • fig = plt.figure()
      • fig.add_axes([0.1, 0.1, 0.8, 0.8])
      • fig.add_subplot(111)
    • https://www.zhihu.com/question/51745620(这里面还有作者对于面向对象和面向过程编程的思考和建议哦)

  • spines

    • 轴脊线-记录数据区域边界的线
    • gca
      • get current axes
    • 获取图像的轴,总共有四个轴top、bottom、left和right
    • plt.spines[‘top’]
    • plt.spines[‘top’].set_color()
      • plt.spines[‘right’].set_color(‘none’)(隐藏坐标轴)
    • plt.spines[‘top’].set_position()

主要函数的参数

  • color
    • 颜色
  • marker
    • 点型
    • linestyle
    • 线型
  • linewidth
    • 线宽
  • loc
    • 位置
  • ncol
  • nbins
    • 格数
  • size
    • 大小
  • family
    • 字体
  • style
    • 字体风格
  • bbox
    • 边框
  • alpha
    • 透明度
  • weight
    • 粗细
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值