如何使用 python 在 matplotlib 中绘制子图,如图所示

How to plot subplots in matplotlib as show in the image using python

我想在橙色区域绘制一张图,在蓝色和红色区域分别绘制一张图。我正在尝试以下方式。有没有办法做到这一点?任何帮助将不胜感激。

import pandas as pd
import matplotlib.pyplot as plt


data =  pd.read_csv("data.csv")


fig = plt.figure()
plt.style.use('seaborn')

plt.tight_layout()

ax1 = plt.subplot(22[1:2])
ax1.plot(data.time_stamp,data.cell_1)

ax2 = plt.subplot(223)
ax2.plot(data.time_stamp,data.cell_2)

ax3 = plt.subplot(224)
ax3.plot(data.time_stamp,data.cell_3)

plt.show()

您可能想试试add_axes()功能,网上有教程和展示。

您可以使用GridSpec来定义每个子图的维度。

from matplotlib.gridspec import GridSpec

fig = plt.figure()
grid = GridSpec(2,2, figure=fig)
ax1 = fig.add_subplot(grid[0,:])
ax2 = fig.add_subplot(grid[1,0])
ax3 = fig.add_subplot(grid[1,1])
for ax in fig.axes:
    ax.set_xticks([])
    ax.set_yticks([])