python matplotlib fig = plt.figure() fig.add_subplot()

一、matplotlib.pyplot.figure()

Create a new figure, or activate an existing figure.
matplotlib官网
功能: 创建一个新的图形 或激活一个已有的图形
**注意: 若不添加描述,默认图形描述为figure1; **
形如plt.figure(‘新的图形’)为图形添加自定义描述

(1)figure语法说明

figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True)

num: 图像编号或名称,数字为编号 ,字符串为名称
figsize: 指定figure的宽和高,单位为英寸;如figsize=(5,4)
dpi: Dots Per Inch 指定绘图对象的分辨率,即每英寸多少个像素,缺省值为80 。 若设置dpi=20, 则画面会非常模糊。(1英寸等于2.5cm,A4纸是 21*30cm的纸张)
facecolor: 背景颜色
edgecolor: 边框颜色
frameon: 是否显示边框

二、在figure中添加子图

没有add_subscatter(), add_subplot()意为添加子图并设置子图在整个figure中的位置,至于图的类型设置为下一步
add_subplot(nrows,ncols,sharex,sharey,subplot_kw)
在这里插入图片描述

三、简单示例

import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
# 从本地字体集中导入‘宋体’,以免出现汉字乱码的情况
font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=15)
# 在"figure1"中创建一个带有散点图
# sin和cos 同时存在一个图中,使用label参数区分;alpha:RGBA空间中用于控制不透明度的值,范围为0-1;
plt.scatter(np.arange(0, 5, 0.1), np.sin(np.arange(0, 5, 0.1)), c = 'Pink', label = 'sin', alpha = 0.7)
plt.scatter(np.arange(0, 5, 0.1), np.cos(np.arange(0, 5, 0.1)), c = 'Pink', label = 'cos')
# 添加一个新的figure
fig = plt.figure('新的画布')
# 在新的figure中创建两行两列的四子图, 并且标注位置
fig.add_subplot(2,2,1)
fig.add_subplot
  • 4
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值