Python - Organisation of 3 subplots with matplotlib

点点圈 提交于 2019-12-03 01:25:18

This is probably a lot easier if you use GridSpec:

import numpy as np
import matplotlib.pylab as pl
import matplotlib.gridspec as gridspec

# Create 2x2 sub plots
gs = gridspec.GridSpec(2, 2)

pl.figure()
ax = pl.subplot(gs[0, 0]) # row 0, col 0
pl.plot([0,1])

ax = pl.subplot(gs[0, 1]) # row 0, col 1
pl.plot([0,1])

ax = pl.subplot(gs[1, :]) # row 1, span all columns
pl.plot([0,1])

See: http://matplotlib.org/users/gridspec.html

The same as the above answer can be done with a figure object like so:

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

# Create 2x2 sub plots
gs = gridspec.GridSpec(2, 2)

fig = plt.figure()
ax1 = fig.add_subplot(gs[0, 0]) # row 0, col 0
ax1.plot([0,1])

ax2 = fig.add_subplot(gs[0, 1]) # row 0, col 1
ax2.plot([0,1])

ax3 = fig.add_subplot(gs[1, :]) # row 1, span all columns
ax3.plot([0,1])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!