python中plot是什么意思_python – “plt.figure”有什么意义?

本文详细介绍了在Python的matplotlib库中如何使用plt.figure()函数。它在创建图形、设置图形参数以及管理多个图形之间的作用被清晰地阐述。plt.figure()的三种主要用途包括获取图形句柄、设置图形参数和创建新图形。此外,还提到了在不需要显式调用plt.figure()的情况下,如何默认创建和切换图形,并推荐使用plt.subplots()来管理和绘制多个轴。
摘要由CSDN通过智能技术生成

import numpy as np

import matplotlib.pyplot as plt

def f(t):

return np.exp(-t) * np.cos(2*np.pi*t)

t1 = np.arange(0.0, 5.0, 0.1)

t2 = np.arange(0.0, 5.0, 0.02)

plt.figure(1)

plt.subplot(211)

plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')

plt.subplot(212)

plt.plot(t2, np.cos(2*np.pi*t2), 'r--')

plt.show()

“If num is provided, and a figure with this id already exists, make it

active, and returns a reference to it. “

我尝试在没有plt.figure的情况下在我的Ipython上执行上述操作,但它仍然显示了两张所需的图片.

解决方法:

plt.figure有三种情况有用:

>获取图形的句柄.在许多情况下,拥有图形的句柄是有用的,即用于存储matplotlib.figure.Figure实例的变量,以便稍后可以使用它.例:

fig = plt.figure()

#... other code

fig.autofmt_xdate()

>设置图形参数.为图设置一些参数的选项是将它们作为参数提供给plt.figure,例如,

plt.figure(figsize=(10,7), dpi=144)

>创建几个数字.为了在同一个脚本中创建多个图形,可以使用plt.figure.例:

plt.figure() # create a figure

plt.plot([1,2,3])

plt.figure() # create another figure

plt.plot([4,5,6]) # successive commands are plotted to the new figure

在许多其他情况下,实际上不需要使用plt.figure.使用pyplot接口,调用任何绘图命令就足以创建一个图形,并且您始终可以使用plt.gcf()获取当前图形的句柄.

从另一个角度来看,通常不仅需要具有图形的手柄而且还需要具有要绘制的轴.在这种情况下,使用plt.subplots更有利,fig,ax = plt.subplots().

标签:python,python-3-x,matplotlib

来源: https://codeday.me/bug/20190724/1522474.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值