matplotlib pyplot subplots

绘制图片

import 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()

在这里插入图片描述

绘制子图

# 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

from 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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

或许,这就是梦想吧!

如果对你有用,欢迎打赏。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值