Python -- matplotlib:plt.ion()、plt.ioff()、plt.show()三者的关系、用法及其代码尝试

本文详细介绍了Matplotlib库中plt.ion(), plt.ioff()和plt.show()的使用,通过实例演示了交互模式、阻塞模式的切换以及它们在混合场景中的应用。读者将掌握如何在不同模式下创建和显示figure。
摘要由CSDN通过智能技术生成
  1. plt.ion():将 figure 设置为交互模式,figure 不用 plt.show() 也可以显示。

  2. plt.ioff():将 figure 设置为阻塞模式,也是 figure 的默认模式,figure 必须用 plt.show() 才能显示。

  3. plt.show():显示所有的 figure(不管是阻塞模式的还是交互模式的)。若一个 figure 下一个 plt.show(),则只有关闭一个 figure,才会出现下一个 figure。若最后设置 plt.show(),则会显示设置的所有 figure。

  4. 运用代码加深理解:

    4.1 交互模式下的尝试

    import matplotlib.pyplot as plt
    plt.ion()
    plt.figure()
    

    4.2 阻塞模式下的尝试

    import matplotlib.pyplot as plt
    # plt.ioff()
    plt.figure()
    

    4.3.1 混合模式下1

    import matplotlib.pyplot as plt
    plt.figure()
    plt.ion()
    plt.figure()
    

    4.3.2 混合模式下2

    import matplotlib.pyplot as plt
    plt.figure()
    plt.ion()
    plt.figure()
    plt.show()
    

    4.4 show下的模式

    import matplotlib.pyplot as plt
    plt.figure()
    plt.show()
    plt.figure()
    plt.show()
    
  • 10
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值