matplotlib画图

本文介绍了Python中使用Matplotlib库进行图像绘制的基础知识,包括创建figure对象,设置参数如dpi、facecolor和edgecolor,以及如何使用ImageGrid创建多个子图。示例中展示了如何关闭坐标轴,以及绘制折线图的方法,包括两种不同的plot调用方式。文章还提供了官方文档链接供深入学习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

from matplotlib.colors import Normalize
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np
import matplotlib
from typing import List

利用上面的头文件进行画图

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

num:图像编号或名称,数字为编号 ,字符串为名称
figsize:指定figure的宽和高,单位为英寸;
dpi参数指定绘图对象的分辨率,即每英寸多少个像素,缺省值为80 1英寸等于2.5cm,A4纸是 21*30cm的纸张
facecolor:背景颜色
edgecolor:边框颜色
frameon:是否显示边框
参考:python中的figure什么意思_plt.figure()参数使用详解及运行演示

grid = ImageGrid(fig, 
				111,#与subplot(111)相似
                nrows_ncols=(n_rows, n_columns),#设置n_rows* n_columns大小的坐标系
                axes_pad=(0.1, 0.3),#pad between axes in inch
                direction='row',#Whether axes are created in row-major ("row by row") or column-major order ("column by column"). This also affects the order in which axes are accessed using indexing (grid[index]).
                     )#这里已经相当于构建了一个大的坐标系

参考:

官网文档1
官网文档2

    ax2 = fig.add_subplot(233)#第一个表示行,第二个表示列,第三个表示这个图的位置
    ax2.imshow(img_q)
    ax2.axis('off')#去除坐标系

折线图

data = np.random.randn(10).cumsum()
data1 = np.random.randn(10)#.cumsum()
#data
#method1
plt.plot(data,'g--')
plt.plot(data1,'k--')
plt.title('data')
#method2
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(data,'g--')
ax.plot(data1,'k')

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值