当前位置:   article > 正文

matplotlib绘制多张图、多子图、多例图_matplotlib同时绘制8个图

matplotlib同时绘制8个图

绘制多图

关键:
fig = plt.figure(1) 表示新建第几个图

import matplotlib.pyplot as plt

fig = plt.figure(1)
plt_rec_loss = [1,2,3,4,5,6]
plt_rec_recall = [4,3,6,5,8,9]
plt.xlabel("epoch")
plt.ylabel("loss")
plt.plot(range(len(plt_rec_loss)), plt_rec_loss)

fig = plt.figure(2)
plt.xlabel("epoch")
plt.ylabel("recall")
plt.plot(range(len(plt_rec_recall)), plt_rec_recall)

plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

在这里插入图片描述

绘制多例图

import matplotlib.pyplot as plt

plt_rec_loss = [1,2,3,4,5,6]
plt_rec_recall = [4,3,6,5,8,9]
plt.xlabel("epoch")
plt.ylabel("test")
plt.plot(range(len(plt_rec_loss)), plt_rec_loss)
plt.plot(range(len(plt_rec_recall)), plt_rec_recall, color="r")

plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

在这里插入图片描述

绘制多个子图

关键:
plt.subplot(211) 将画布分为2行1列,这个子图位于被划分的画布的第一块子图位置。
plt.subplot(212) 将画布分为2行1列,这个子图位于被划分的画布的第二块子图位置。

import matplotlib.pyplot as plt

plt_rec_loss = [1,2,3,4,5]
plt_rec_recall = [4,3,6,7,8,9]
ax1 = plt.subplot(211)
plt.xlabel("epoch")
plt.ylabel("loss")
plt.plot(range(len(plt_rec_loss)), plt_rec_loss)
ax2 = plt.subplot(212)
plt.xlabel("epoch")
plt.ylabel("recall")
plt.plot(range(len(plt_rec_recall)), plt_rec_recall, color="r")
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/612719
推荐阅读
相关标签
  

闽ICP备14008679号