Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of figure when using plt.subplots

I'm having some trouble trying to change the figure size when using plt.subplots. With the following code, I just get the standard size graph with all my subplots bunched in (there's ~100) and obviously just an extra empty figuresize . I've tried using tight_layout, but to no avail.

def plot(reader):     channels=[]     for i in reader:         channels.append(i)      plt.figure(figsize=(50,100))     fig, ax = plt.subplots(len(channels), sharex=True)      plot=0         for j in reader:           ax[plot].plot(reader["%s" % j])         plot=plot+1      plt.tight_layout()     plt.show() 

any help would be great!

enter image description here

like image 227
Ashleigh Clayton Avatar asked Nov 12 '13 15:11

Ashleigh Clayton


People also ask

How does subplot change figure size?

To change figure size of more subplots you can use plt. subplots(2,2,figsize=(10,10)) when creating subplots.

What is PLT figure size?

figsize() takes two parameters- width and height (in inches). By default the values for width and height are 6.4 and 4.8 respectively. Syntax: plt.figure(figsize=(x,y)) Where, x and y are width and height respectively in inches.

What is the difference between PLT figure and PLT subplots?

figure() − Creates a new figure or activates an existing figure. plt. subplots() − Creates a figure and a set of subplots.

What is the default figure size in Matplotlib?

If not provided, defaults to rcParams["figure. figsize"] (default: [6.4, 4.8]) = [6.4, 4.8] .


1 Answers

You can remove your initial plt.figure(). When calling plt.subplots() a new figure is created, so you first call doesn't do anything.

The subplots command in the background will call plt.figure() for you, and any keywords will be passed along. So just add the figsize keyword to the subplots() command:

def plot(reader):     channels=[]     for i in reader:         channels.append(i)      fig, ax = plt.subplots(len(channels), sharex=True, figsize=(50,100))      plot=0         for j in reader:           ax[plot].plot(reader["%s" % j])         plot=plot+1      plt.tight_layout()     plt.show() 
like image 82
Rutger Kassies Avatar answered Sep 18 '22 22:09

Rutger Kassies