Python使用add_subplot与subplot画子图操作


本文摘自php中文网,作者不言,侵删。

这篇文章主要介绍了Python使用add_subplot与subplot画子图操作,涉及Python使用matplotlib模块进行图形绘制的相关操作技巧,需要的朋友可以参考下

本文实例讲述了Python使用add_subplot与subplot画子图操作。分享给大家供大家参考,具体如下:

子图:就是在一张figure里面生成多张子图。

Matplotlib对象简介

FigureCanvas 画布
Figure 图
Axes 坐标轴(实际画图的地方)

注意,pyplot的方式中plt.subplot()参数和面向对象中的add_subplot()参数和含义都相同。

使用面向对象的方式

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

#!/usr/bin/python

#coding: utf-8

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(0, 100)

fig = plt.figure()

ax1 = fig.add_subplot(221)

ax1.plot(x, x)

ax2 = fig.add_subplot(222)

ax2.plot(x, -x)

ax3 = fig.add_subplot(223)

ax3.plot(x, x ** 2)

ax4 = fig.add_subplot(224)

ax4.plot(x, np.log(x))

plt.show()

pyplot的方式

1

2

3

4

5

6

7

8

9

10

11

12

13

14

#!/usr/bin/python

#coding: utf-8

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(0, 100)

plt.subplot(221)

plt.plot(x, x)

plt.subplot(222)

plt.plot(x, -x)

plt.subplot(223)

plt.plot(x, x ** 2)

plt.subplot(224)

plt.plot(x, np.log(x))

plt.show()

运行结果:

相关推荐:

Python使用Windows API创建窗口示例

以上就是Python使用add_subplot与subplot画子图操作的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python字典中如何添加键值对

Python model怎么用

Python学习有哪些网站

什么是Python re.compile 函数?

Python注释符是什么意思

Python中dict是什么

Python随机密码的生成教程

r和Python哪个容易入门

Python中title()方法的使用

如何利用Python刷访问量

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...