matplotlib.pyplot分区绘图

这里没有过多强调细节,这里只给出使用方法

方法一:使用plt.subplot函数

plt.figure
plt.subplot(1,2,1) #表示1行2列的第一个区域
plt.plot(..)
plt.legend(..)
plt.xlabel(..)
plt.ylabel(..)

plt.subplot(1,2,2) #表示1行2列的第二个区域
plt.plot(..)
plt.legend(..)
plt.xlabel(..)
plt.ylabel(..)

plt.show()

方法二:使用plt.subplots()函数 

import matplotlib.pyplot as plt

fig, ax = plt.subplots(1,2)

ax[0].plot([3,2,1])
ax[0].legend('bb')
ax[0].set_xlabel('[0, 0]')


ax[1].plot([1,2,3]) #0,1表示选中第0行第1列的ax子图
ax[1].legend('aa')
ax[1].set_xlabel('[0, 1]')

plt.show()

关于一些细节的设置,可以参考我的另一篇博文:https://blog.csdn.net/qq_41368074/article/details/116669086

更复杂的用法,参考这篇博客的plt.subplot2grid函数用法:https://www.cnblogs.com/yoyo1216/p/10131662.html

本文参考:https://blog.csdn.net/wc881108/article/details/107656015


版权声明:本文为qq_41368074原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。