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-');
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With