python中subplot函数怎么画图?

447次阅读
没有评论

python中subplot函数怎么画图?

python中subplot函数说明

(1)调用subplot()函数可以创建子图,程序可以在子图上绘制。subplot(nrows、ncols、index、**kwargs)函数的nrows参数指定将数据图区域分成多少行,ncols参数指定将数据图区域分成多少列,index参数指定获得多少区域。

(2)subplot()函数还支持直接输入一个三位数的参数,其中第一位数是nrows参数;第二位数是ncols参数;第三位数是index参数。

python中subplot函数的参数

nrows:  subplot的行数

ncols: subplot的列数

sharex :所有subplot应该使用相同的X轴刻度(调节xlim将会影响所有的subplot)

sharey: 所有subplot应该使用相同的Y轴刻度(调节ylim将会影响所有的subplot)

subplot_kw: 用于创建各subplot的关键字字典

**fig_kw: 创建figure时的其他关键字

python中subplot函数实例

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 100)
#作图1
plt.subplot(2,2,1)  #等效于plt.subplot(221)
plt.plot(x, x)
#作图2
plt.subplot(2,2,2)
plt.plot(x, -x)
#作图3
plt.subplot(2,2,3)
plt.plot(x, x ** 2)
plt.grid(color='r', linestyle='--', linewidth=1,alpha=0.3)
#作图4
#plt.subplot(224)
#plt.plot(x, np.log(x))
plt.show()
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-04-24发表,共计758字。
新手QQ群:570568346,欢迎进群讨论 Python51学习