Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot 5 subplots in two rows using matplotlib or seaborn? [duplicate]

How do I plot 5 subplots instead of 6 plots as a output to a jupyter notebook cell. I'm trying to plot 5 separate subplots but when I tried using,

fig, ax = plt.subplots(2, 3, figsize=(10, 7))

This is returning 6 subplots in two rows and three columns. What I'm trying to achieve is plotting 5 subplots in two rows?

Eg: In first row I need three subplots and in second row I need only two subplots instead of there.

How can I achieve this using matplotlib or seaborn?

like image 259
user24046 Avatar asked Jul 19 '19 05:07

user24046


1 Answers

import matplotlib.pyplot as plt
import numpy as np
fig=plt.figure(figsize=(10,7))
columns = 3
rows = 2
a=np.random.rand(2,3)
for i in range(1, 6):
    fig.add_subplot(rows, columns, i)
    plt.plot(a)### what you want you can plot  
plt.show()

output

like image 108
Rahul Verma Avatar answered Oct 03 '22 09:10

Rahul Verma