绘制图片
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16import numpy as np import matplotlib.pyplot as plt # 双变量的直方图 # 颜色越深频率越高 # 研究双变量的联合分布 x = np.arange(2).reshape(-1,1) y = np.arange(2,4).reshape(-1,1) z = np.hstack([x, y]) # 横向连接两个矩阵 ax1 = plt.imshow(z) plt.colorbar() plt.xlabel('activities') plt.ylabel('sensor') plt.title('significance analysis') plt.show()
绘制子图
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21# import matplotlib.pyplot as plt import numpy as np def f(t): s1 = np.cos(2*np.pi*t) e1 = np.exp(-t) return s1 * e1 t1 = np.arange(0.0, 5.0, 0.1) t2 = np.arange(0.0, 5.0, 0.02) t3 = np.arange(0.0, 2.0, 0.01) fig, axs = plt.subplots(2, 2, constrained_layout=True) axs[0][1].plot(t1, f(t1), 'o', t2, f(t2), '-') axs[0][1].set_title('subplot 1') axs[0][1].set_xlabel('distance (m)') axs[0][1].set_ylabel('Damped oscillation') fig.suptitle('This is a somewhat long figure title', fontsize=16) axs[1][0].plot(t3, np.cos(2*np.pi*t3), '--') axs[1][0].set_xlabel('time (s)') axs[1][0].set_title('subplot 2') axs[1][0].set_ylabel('Undamped') plt.show()
防止 plt
out of memory
复制代码
1
2
3
4
5
6
7
8
9
10from matplotlib import pyplot while True: fig = pyplot.figure() ax = fig.add_subplot(111) ax.plot(x,y) ax.legend(legendStrings, loc = 'best') fig.savefig('himom.png') plt.clf() # etc....
ref
matplotlib.pyplot.legend
Customizing Matplotlib with style sheets and rcParams
matplotlib.pyplot.subplots
Controlling the position and size of colorbars with Inset Axes
matplotlib.pyplot.subplots_adjust
Only Using Plt.Close. (2021) python - Matplotlib runs out of memory when plotting in a loop - Stack Overflow. Retrieved April 06, 2021, from https://stackoverflow.com/questions/2364945/matplotlib-runs-out-of-memory-when-plotting-in-a-loop
最后
以上就是碧蓝水杯最近收集整理的关于matplotlib pyplot subplots的全部内容,更多相关matplotlib内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复