Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

figure size does not respond to my figsize setting in plt.figure() with matplotlib in my jupyter notebook

I was trying to change the figure size of my plot with matplotlib. But the actual figure size I got does not change to different figsize setting in plt.figure(). I'm totally confused about why it happened. Could anyone help me with that? Below is the sample code. I'm using jupyter notebook. Thanks a lot.

import matplotlib.pyplot as plt
%matplotlib inline
x = np.arange(1,5,1)
fig = plt.figure(figsize=(10,5))
fig, ax = plt.subplots(nrows=1, ncols=2)
ax = ax.flatten()
ax[0].plot(x, x+2, 'k-')
ax[1].plot(x, 2*x+5, 'k-');
like image 909
zesla Avatar asked Dec 08 '25 21:12

zesla


1 Answers

You are creating two figures. The one has the size set to (10,5), the other is the one that you plot to. Remove the line fig = plt.figure(figsize=(10,5)) and add figsize=(10,5) to the figure you want to show.

fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(10,5))
like image 96
ImportanceOfBeingErnest Avatar answered Dec 11 '25 12:12

ImportanceOfBeingErnest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!