为了清楚起见,我将使用一个4x4网格来显示我想要的子图的位置和大小.计数如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
我想将顶部图放置在2,3,6和7上.两个底部图分别是9,10,13,14和11,12,15,16.在Matlab中,您可以使用子图范围,但我相信这仅适用于单行配置.
我怎么能在matplotlib中这样做?我需要一个gridspec吗?那我怎么用呢?这些例子不足以理解我应该如何解决这个问题.
使用subplot
范围:
img = imread('cameraman.tif'); figure; subplot(4,4,[2 3 6 7]);imshow(img); subplot(4,4,[9 10 13 14]);imshow(img); subplot(4,4,[11 12 15 16]);imshow(img);
结果是:
matplotlib
基于的解决方案subplot2grid
import matplotlib.pyplot as plt plt.subplot2grid( (4,4), [0,1], 2, 2 ) plt.plot( x1, y1 ) plt.subplot2grid( (4,4), [2,0], 2, 2 ) plt.plot( x2, y2 ) plt.subplot2grid( (4,4), [2,2], 2, 2 ) plt.plot( x2, y2 )
给出以下结果: