Python第三方库——Matplotlib库

本文详细介绍了Python的Matplotlib库,包括pyplot模块、figure模块、axes模块和gridspec模块的使用方法,如创建子图、设置坐标轴标签、显示图像等。并展示了实践案例——绘制confusion matrix,同时探讨了在图表中显示中文信息的配置方法。
摘要由CSDN通过智能技术生成

import matplotlib.pyplot as plt

pyplot模块

  • plt.ion():打开交互模式

  • plt.figure(num=None, figsize=None, dpi=None,
    facecolor=None, edgecolor=None, frameon=True,
    FigureClass=<class 'matplotlib.figure.Figure'>, **kwargs)

    参数:
    num:整数或者字符串,默认值是None。figure对象的id。如果没有指定num,那么会创建新的figure,id(也就是数量)会递增,这个id存在figure对象的成员变量number中;如果指定了num值,那么检查id为num的figure是否存在,存在的话直接返回,否则创建id为num的figure对象,并且如果num是字符串类型,窗口的标题会设置成num。
    fsize:整数元组,默认值是None。表示宽、高的inches数。
    dpi:整数,默认值为None。表示figure的分辨率
    facecolor:背景颜色
    edgecolor:边缘颜色
    返回:
    figure:Figure对象

  • ax = plt.subplot(*args, **kwargs)
    关键字参数
    facecolor:subplot的背景颜色
    projection:
    返回:

subplot(nrows, nclos, plot_number)#将figure划分成nrows行ncols列个子坐标。plot_number用来返回指定的subplot,从1开始,先横向后纵向
#当行、列和plot_number都小于10的时候,可以用下面的简单的调用形式来指定行列数及plot_number
subplot(211)

            例子

import matplotlib.pyplot as plt
# plot a line, implicitly creating a subplot(111)
plt.plot([1,2,3])

# now create a subplot which represents the top plot of a grid with 2 rows and 1 column. 
#Since this subplot will overlap the
# first, the plot (and its axes) previously created, will be removed
plt.subplot(211)
plt.plot(range(12))
plt.subplot(212, facecolor='y') # creates 2nd subplot with yellow background
  • fig, ax = plt.subplots(nrows=1, ncols=1, sharex=False,
    sharey=False, squeeze=Tru

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值