python plot figure_在matplotlib中使用plot、axes或figure绘制绘图有什么区别?

方法1plt.plot(x, y)

这样,您只需绘制一个具有(x,y)坐标的图形。如果你只想得到一个图形,你可以用这种方式。

方法2ax = plt.subplot()

ax.plot(x, y)

这样可以在同一窗口中绘制一个或多个图形。当你写的时候,你只会画出一个图形,但是你可以这样做:fig1, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)

您将在同一窗口中绘制4个图形,分别命名为ax1、ax2、ax3和ax4。这个窗口将用我的例子分成4部分。

方法3fig = plt.figure()

new_plot = fig.add_subplot(111)

new_plot.plot(x, y)

我没用,但你可以找到文件。

示例:import numpy as np

import matplotlib.pyplot as plt

# Method 1 #

x = np.random.rand(10)

y = np.random.rand(10)

figure1 = plt.plot(x,y)

# Method 2 #

x1 = np.random.rand(10)

x2 = np.random.rand(10)

x3 = np.random.rand(10)

x4 = np.random.rand(10)

y1 = np.random.rand(10)

y2 = np.random.rand(10)

y3 = np.random.rand(10)

y4 = np.random.rand(10)

figure2, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)

ax1.plot(x1,y1)

ax2.plot(x2,y2)

ax3.plot(x3,y3)

ax4.plot(x4,y4)

plt.show()

d2a4594c51ef9da84fc56d565596445c.png44abdb96ed6f992b18f65dea60482ae3.png

其他示例:

2997a7418cc96e9d6f7543e2d6761609.png

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值