matplotlib1. --- 几个画图之前的核心点Axes, Figure,Axis

作图环境:vscode+插件Jupyter

在这里插入图片描述
这段话很重要:
一个作图的窗口就是一个Figure, 在Figure上可以有很多个Axes/Subplot,每一个Axes/Subplot为一个单独的绘图区,可以在上面绘图,其中每一个Axes/subplot, 有XAxis,YAxis,在上面可以标出刻度,刻度的位置,以及xy轴的标签label。

下图为一个Figure上更详细的内容:
在这里插入图片描述

  1. 创建Figure
    plt.figure
    https://matplotlib.org/api/_as_gen/matplotlib.pyplot.figure.html
  • 常用的一个参数: figsize=(width, height), 可以指定(w,h),也可以用figaspect(ratio)计算。创建指定宽度和高度的Figure
  • Return : 返回的是一个Figure窗体对象

函数:figaspect(ratio) https://matplotlib.org/api/_as_gen/matplotlib.figure.figaspect.html?highlight=figaspect#matplotlib.figure.figaspect
rcParams["figure.figsize"],取出height,并利用 r a t i o = h e u g h t w i d t h ratio = \frac{heught}{width} ratio=widthheught计算出width,返回(width, height)

import matplotlib.pyplot as plt
fig = plt.figure(figsize=plt.figaspect(2.0)) # an empty figure with no axes
fig.suptitle("No axec on this figure")  # Add a title so we know which it is


在这里插入图片描述

  1. 在Figure上创建Axes
    所有的画图工作都在Axes上执行,一个Figure可以有很多个Axes,但是一个Axes只能属于一个Figure.

一般来说,你会创建一个Figure,然后再将Axes添加到Figure上。

你可能会使用fig.add_axes,但是,更多的时候使用fig.add_subplot更方便。
add_subplot(*args, **kwargs)
https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html?highlight=add_subplot#matplotlib.figure.Figure.add_subplot

  • return : Axes实例
# 调用实例
add_subplot(nrows, ncols, index, **
  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值