I have a script like this which when executed opens up a new window with the figure.
import matplotlib.pyplot as plt
fig = plt.Figure()
# ax = fig.add_axes(rect=(0.1, 0.0, 0.9, 1.0)) # does not open a new window
ax = fig.add_subplot() # works
plt.show()
The problem is that when I use the add_axes
function, the plt.show()
call seems to do nothing at all.
The fig.savefig
still seems to work, but I would like to see the figure by plt.show
as well. Any ideas? Thanks
Use plt.figure()
instead of plt.Figure()
. They are different:
import matplotlib.pyplot as plt
fig = plt.figure() # replaced Figure with figure
ax = fig.add_axes(rect=(0.1, 0.0, 0.9, 1.0))
ax = fig.add_subplot() # works
plt.show()
plt.Figure()
creates a new Figure
objectplt.figure()
creates a new Figure
object and also sets it as the current figure in the pyplot state.