Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I arrange 3 equally sized subplots in a triangular shape?

To make this clear, I will use an 4x4 grid to show where and how large I want my subplots. The counting goes like this:

1  2  3  4
5  6  7  8
9  10 11 12
13 14 15 16

I want the top plot to be placed over 2, 3, 6, and 7. The two bottom plots are then 9, 10, 13, 14 and 11, 12, 15, 16, respectively. In Matlab, you can use a subplot range, but I believe this only works for single row configurations.

How can I do this in matplotlib? Do I need a gridspec? How would I use it then? The examples are insufficient to understand how I should tackle this problem.

like image 435
rubenvb Avatar asked Dec 02 '13 09:12

rubenvb


People also ask

How can you plot subplots with different sizes?

Create Different Subplot Sizes in Matplotlib using Gridspec The GridSpec from the gridspec module is used to adjust the geometry of the Subplot grid. We can use different parameters to adjust the shape, size, and number of columns and rows.

Can there be multiple subplots?

Sometimes it is helpful to compare different views of data side by side. To this end, Matplotlib has the concept of subplots: groups of smaller axes that can exist together within a single figure. These subplots might be insets, grids of plots, or other more complicated layouts.

What will PLT subplot 333 do?

subplot(333) do? Create a blank plot that fills the figure. Create a plot with three points at location (3,3). Create a smaller subplot in the topleft of the figure.


1 Answers

Use subplot with range:

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);

And the result is:


A matplotlib solution based on 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 )

Gives the following result:

enter image description here

like image 93
Shai Avatar answered Nov 15 '22 16:11

Shai