理解title和suptitle的区别以及动态图中显示title

'''
Author: 365JHWZGo
Description: matplotlib--title
Date: 2021/11/5 18:09
FilePath: day1105-2.py
'''
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 20, 1)
y1 = 2 * x + np.random.rand(20)
y = 2 * x

plt.scatter(x, y1,c = 'r', label='scatter')
plt.plot(x, y, color='b', lw=1, label='line')
plt.legend()
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.title('figure')
plt.show()

在这里插入图片描述

'''
Author: 365JHWZGo
Description: matplotlib--title
Date: 2021/11/5 18:09
FilePath: day1105-2.py
'''
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 20, 1)
y1 = 2 * x + np.random.rand(20)
y = 2 * x

plt.scatter(x, y1,c = 'r', label='scatter')
plt.plot(x, y, color='b', lw=1, label='line')
plt.legend()
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.suptitle('figure1')
plt.show()

在这里插入图片描述
通过对比明显可以看到suptitle比title的显示位置靠上

TIP:

'''
Author: 365JHWZGo
Description: matplotlib --- plt.draw()
Date: 2021/11/5 15:29
FilePath: day1105-1.py
'''

# 导包
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-10, 10, 10)

plt.figure(num=1, figsize=(5, 5))
plt.ion()

for j in range(5):
    for i in range(20):
        plt.cla()
        plt.ylim((0, 1000))
        plt.plot(x, i * x ** 2 + 2 * x + 1, 'r-')
        plt.title('dynamic picture')
        plt.draw()
        plt.pause(0.05)
    for i in range(20, -1, -1):
        plt.cla()
        plt.ylim((0, 1000))
        plt.plot(x, i * x ** 2 + 2 * x + 1, 'r-')
        plt.title('dynamic picture')
        plt.draw()
        plt.pause(0.05)
# plt.suptitle('动态展示',fontsize = 12,color = 'r-')
plt.ioff()

plt.show()

当title写在其他位置时,不显示,只有在plot下才显示,因此需要注意在动态显示图时,把title放在plot下
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

365JHWZGo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值