plt.show() results in an empty plot figure
Question:
plt.show() isn’t working in Matplotlib Python
My Code:
# Python program to show pyplot module
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
# Creating a new figure with width = 5 inches
# and height = 4 inches
fig = plt.figure(figsize =(5, 4))
# Creating a new axes for the figure
ax = fig.add_axes([1, 1, 1, 1])
# Adding the data to be plotted
ax.plot([2, 3, 4, 5, 5, 6, 6],
[5, 7, 1, 3, 4, 6 ,8])
plt.show()
I was expecting a graph but a blank screen opens in front of me:

Answers:
In the line ax = fig.add_axes([1, 1, 1, 1])
, the values [1, 1, 1, 1] represent the left, bottom, width, and height of the axes, respectively. These values specify the position and size of the axes within the figure.
In your code, the values [1, 1, 1, 1] mean that the axes cover the entire figure.
Modify the code like this for example:
# Python program to show pyplot module
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
# Creating a new figure with width = 5 inches
# and height = 4 inches
fig = plt.figure(figsize =(5, 4))
# Creating a new axes for the figure
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
# Adding the data to be plotted
ax.plot([2, 3, 4, 5, 5, 6, 6],
[5, 7, 1, 3, 4, 6 ,8])
plt.show()
plt.show() isn’t working in Matplotlib Python
My Code:
# Python program to show pyplot module
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
# Creating a new figure with width = 5 inches
# and height = 4 inches
fig = plt.figure(figsize =(5, 4))
# Creating a new axes for the figure
ax = fig.add_axes([1, 1, 1, 1])
# Adding the data to be plotted
ax.plot([2, 3, 4, 5, 5, 6, 6],
[5, 7, 1, 3, 4, 6 ,8])
plt.show()
I was expecting a graph but a blank screen opens in front of me:
In the line ax = fig.add_axes([1, 1, 1, 1])
, the values [1, 1, 1, 1] represent the left, bottom, width, and height of the axes, respectively. These values specify the position and size of the axes within the figure.
In your code, the values [1, 1, 1, 1] mean that the axes cover the entire figure.
Modify the code like this for example:
# Python program to show pyplot module
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
# Creating a new figure with width = 5 inches
# and height = 4 inches
fig = plt.figure(figsize =(5, 4))
# Creating a new axes for the figure
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
# Adding the data to be plotted
ax.plot([2, 3, 4, 5, 5, 6, 6],
[5, 7, 1, 3, 4, 6 ,8])
plt.show()