深度学习基础--Matplotlib

Matplotlib

Matplotlib是用于绘制图形的库,使用该库可以轻松地绘制图形和实现数据的可视化。

库的安装

  1. 使用python的pip。

    pip install matplotlib
    
  2. 使用anaconda虚拟环境的话使用conda。

    conda install matplotlib
    

绘制简单图形

import numpy as np
import matplotlib.pyplot as plt

"""Matplotlib绘制简单图形"""

x = np.arange(-5, 5, 0.1)  # 生成从-5到5, 步长为0.1的数据
y_1 = np.sin(x)  # NumPy的sin函数
y_2 = np.cos(x)  # NumPy的cos函数

plt.plot(x, y_1, label="sin")  # plot方法绘图(sin函数图像)
plt.plot(x, y_2, linestyle="--", label="cos")  # plot方法绘图(cos函数图像)
plt.xlabel("x")  # 坐标轴横轴为x
plt.ylabel("y")  # 坐标轴纵轴为y
plt.title("sin & cos")  # 图像标题
plt.legend()  # 为轴上已经存在的线制作图例
plt.show()  # show方法显示图像

运行结果:
在这里插入图片描述

显示图像

pyplot中提供了显示图像的方法imshow()

image模块提供了输入图像的方法imread()

import matplotlib.pyplot as plt
from matplotlib.image import imread
"""显示图像"""
img = imread("Mario.jpg")  # 读入图像
plt.imshow(img)  # 显示图像
plt.show()

注意:

  1. imread传入的是图像的路径,如果图像在项目路径下是可以直接找到的,如果不是可以填绝对路径。

运行结果:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值