当前位置: 首页 > 图灵资讯 > 行业资讯> python中figure()函数画两张图

python中figure()函数画两张图

发布时间:2024-07-30 10:04:26

1、说明

在Python中,Matplotlib是数字-Numpy库的数学扩展。Figure模块提供顶级Artist,即Figure,它包含所有绘图元素。该模块用于控制所有图元的子图和顶级容器的默认间距。

2、实例

如果你想画两张图,你必须使用plt.figure()两次,可以指定num,也可以不指定num,调用两次会默认加1。

importmatplotlib.pyplotasplt
x=[1,2,3]
y1=[1,2,4]
y2=[1,4,8]

plt.figure()
plt.plot(x,y1,color="red",label="red")
plt.legend()#没有这样的句子会显示右下角的label吗?

plt.figure()
plt.plot(x,y2,color="green",label="green")
plt.legend()#如果没有这个句子,右上角的label将不会显示此句子。
plt.show()

以上是python中figure()函数画两张图的方法,希望对大家有所帮助。更多Python学习指导:python基础教程

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09