matplotlib 的 subplot, axes and axis
fig = plt.figure('多图', (10, 10), dpi=80) #第一个指定窗口名称,第二个指定图片大小,创建一个figure对象
plt.subplot(222) #2*2的第二个
plt.axis([0, 6, 0, 20]) #指定坐标轴范围
t = np.arange(0, 5, 0.2)
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') #可以连着写多个 plt.subplot(221) #2*2第一个,这句下面直接写绘图语句和设置语句
x = np.arange(-10, 10, 0.01)
y = np.exp(-x)*np.cos(2*np.pi*x)
plt.plot(x, y, 'r')
plt.xlim([-10, 10]) plt.show()
fig.savefig('linshi.png') #保存figure
2
源自 matplotlib subplot 子图 - Claroja - CSDN博客 http://blog.csdn.net/claroja/article/details/70841382
如果不指定figure()的axes,figure(1)命令默认会被建立,同样的如果不指定subplot(numrows, numcols, fignum)的轴axes,subplot(111)也会自动建立。这里,要注意一个概念当前图和当前坐标。所有绘图操作仅对当前图和当前坐标有效
当前的图表和子图可以使用plt.gcf()和plt.gca()获得,分别表示"Get Current Figure"和"Get Current Axes"。plt.sca (ax1)可以使ax1成为当前axes对象
plt.figure('第一个') # 创建第一个画板(figure)
plt.subplot(211) # 第一个画板的第一个子图
plt.plot([1, 2, 3], [1, 2, 3])
plt.subplot(212) # 第一个画板的第二个子图
plt.plot([4, 5, 6], [1, 2, 3]) plt.figure('第二个') # 创建第二个画板
plt.plot([4, 5, 6], [1, 2, 3]) # 默认子图命令是spbplot(111) plt.figure('第一个') # 如果想对画板1操作,需调取画板1,此时调用中的子图是subplot(212)
plt.subplot(211) # 将调用中的子图变为subplot(211)
plt.title('Easy as 1, 2, 3')
plt.show()
要想重新设置,必须重新调用
3
源自 matplotlib subplot 子图 - Claroja - CSDN博客 http://blog.csdn.net/claroja/article/details/70841382
subplot()是将整个figure均等分割,而axes()则可以在figure上画图。
"""axes的使用""" import matplotlib.pyplot as plt
import numpy as np # 创建数据
dt = 0.001
t = np.arange(0.0, 10.0, dt)
r = np.exp(-t[:1000]/0.05) # impulse response
x = np.random.randn(len(t)) # 从标准正太分布中返回len(t)个随机数
s = np.convolve(x, r)[:len(x)] * dt # colored noise
# 默认主轴图axes是subplot(111)
plt.plot(t, s)
plt.axis([0, 1, 1.1*np.amin(s), 2*np.amax(s)])
plt.xlabel('time(s)')
plt.ylabel('current(nA)')
plt.title('Gaussian colored noise')
# 内嵌图
a = plt.axes([.65, .6, .2, .2], facecolor='y')
# Add an axes to the figure,第一个参数是指定axes的位置和高度,[距左距离,距底距离,宽,高],都是0-1之间,按比例表示
n, bins, patches = plt.hist(s, 400, normed=1)
plt.title('probability')
plt.xticks([]) # 不显示坐标轴标签
plt.yticks([])
# 另外一个内嵌图
b = plt.axes([0.2, 0.6, .2, .2], facecolor='y')
plt.plot(t[:len(r)], r)
plt.title('Impulse response')
plt.xlim(0, 0.2)
plt.xticks([])
plt.yticks([])
plt.show()
可以通过clf()清空当前的图板(figure),通过cla()来清理当前的轴(axes)。你需要特别注意的是记得使用close()关闭当前figure画板
matplotlib 的 subplot, axes and axis的更多相关文章
- Matplotlib中figure、subplot、axes、axis的区别
参考链接:https://blog.csdn.net/JasonZhu_csdn/article/details/85860963 画图板/画布: 这是一个基础载体,类似实际的画图板,用pyplot. ...
- matplotlib中subplot的使用
#plt.subplot的使用 import numpy as npimport matplotlib.pyplot as pltx=[1,2,3,4]y=[5,4,3,2]plt.subplot(2 ...
- python下matplotlib的subplot的多图显示位置的问题
1.说明 1.1 多图: 221,222 212 ------------附最后讲解,这下更清楚了吧,取个名字:颠倒一下--- 1.2 多图 211 223,224 ------------附最后讲解 ...
- matplotlib中subplot的各参数的作用
subplot(a,b,c)中a代表所画图形的行数 b代表所画图形的列数 c代表所画图形的序号. plt.figure(facecolor='w', figsize=(9, 10)) plt.subp ...
- 【Matplotlib-01】Python 绘图库 Matplotlib 入门教程
环境: Windows10 python3.6.4 numpy1.14.1 matplotlib2.1.2 工具:Cmder 目录: 1.线性图 2.散点图 3.饼状图 4.条形图 5.直方图 例1: ...
- matplotlib的读书笔记
matplotlib绘图总结 本文作为学习过程中对matplotlib一些常用知识点的整理,方便查找. 类MATLAB API 最简单的入门是从类 MATLAB API 开始,它被设计成兼容 MA ...
- matplotlib绘图的基本操作
转自:Laumians博客园 更简明易懂看Matplotlib Python 画图教程 (莫烦Python)_演讲•公开课_科技_bilibili_哔哩哔哩 https://www.bilibili. ...
- 数据分析之Matplotlib和机器学习基础
一.Matplotlib基础知识 Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形. 通过 Matplotlib,开发者可以仅需 ...
- matplotlib绘图总结
本文作为学习过程中对matplotlib一些常用知识点的整理,方便查找. 类MATLAB API 最简单的入门是从类 MATLAB API 开始,它被设计成兼容 MATLAB 绘图函数. from p ...
随机推荐
- UEFI + win8 + ubuntu16.04双系统安装
主要参考 https://linux.cn/article-3178-1.html https://linux.cn/article-3061-1.html 其他 https://jingyan.ba ...
- DELETE 语句用于删除表中的行。
DELETE FROM 表名称 WHERE 列名称 = 值
- 【BZOJ】1684: [Usaco2005 Oct]Close Encounter(暴力+c++)
http://www.lydsy.com/JudgeOnline/problem.php?id=1684 这货完全在考精度啊.. 比如奇葩 (llf)a/b*i (llf)(a/b*i)和(llf)( ...
- ORCLE 表中列的修改(非常全面哦)
今天下午主要做了个实验,是针对 测试表的列,进行添加,修改,删除的.做法如下: 增加一列: alter table emp4 add test varchar2(10); 修改一列: alter ta ...
- hdu 2686(状压dp)
题目链接:http://poj.org/problem?id=2686 思路:典型的状压dp题,dp[s][v]表示到达剩下的车票集合为S并且现在在城市v的状态所需要的最小的花费. #include& ...
- iOS开发之--搭建本地的SVN服务器
近期入职的新公司,后台没有分配svn账号,需要在本地搭建一个服务器,方便和代码,看了看网上的教程,一直有这样那样的问题, 其中最主要的问题还是路径拼接的问题,最后终于解决了,特在此分享下,如果大家有更 ...
- sql列转行查询
test表: 执行列转行sql: select student, sum(case Course when '语文' then Score else null end) 语文, sum(case Co ...
- Linux Kernel 4.7版本发布
导读 在经历了长达一周的惬意假日时光,大神Linus Torvalds宣布面向所有GNU/Linux操作系统发布Linux Kernel 4.7.Linux 4.7内核的研发历经2个多月,自今年5月2 ...
- Vmware虚拟机中安装centos,并实现联网
1 安装所需要的软件 vmware workstation 12 永久激活码:5A02H-AU243-TZJ49-GTC7K-3C61N CentOS-7-x86_64-Minimal-1708 2 ...
- js如何计算当前日期的前一个月和后一个月?
<div class="query_title_div"><img src="../../images/task/before.png"/&g ...