Concept Flow - Figure creation with plt.figure
Call plt.figure()
Create new Figure object
Figure ready for plotting
Add plots or axes
Show or save figure
This flow shows how calling plt.figure() creates a new empty figure ready for plotting.
import matplotlib.pyplot as plt fig = plt.figure() print(type(fig))
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Import matplotlib.pyplot as plt | Module imported | plt module ready |
| 2 | Call plt.figure() | Create new figure object | <class 'matplotlib.figure.Figure'> |
| 3 | Print type(fig) | Evaluate type | <class 'matplotlib.figure.Figure'> |
| Variable | Start | After plt.figure() | Final |
|---|---|---|---|
| fig | undefined | Figure object | Figure object |
plt.figure() creates a new empty figure object. Assign it to a variable to modify or add plots. It does not display the figure automatically. Use plt.show() to display the figure. Useful for creating multiple figures in one script.
plt.figure() function do in matplotlib?plt.figure() function creates a new empty figure, which is like a blank canvas for drawing plots.plt.plot() draw on the figure, plt.show() displays it, and plt.savefig() saves it. Only plt.figure() creates the blank space.plt.figure()?figsize, which takes a tuple of (width, height) in inches.figsize=(8, 6) correctly. Others use wrong parameter names or data types.import matplotlib.pyplot as plt fig = plt.figure(figsize=(4, 3), dpi=100) print(fig.get_size_inches()) print(fig.dpi)
figsize is in inches as a float array, so fig.get_size_inches() returns [4. 3.]. The dpi is dots per inch, set to 100.0.fig.get_size_inches() shows floats with decimal points. Printing fig.dpi shows 100.0 as set.import matplotlib.pyplot as plt fig = plt.figure(size=(5, 4)) plt.plot([1, 2, 3], [4, 5, 6]) plt.show()
figsize, not size. Using size causes an error.plt.plot() after plt.figure() is valid. plt.show() has parentheses. Lists have same length.plt.figure() twice, each time creating a new blank canvas.plt.show().Pass the test and this pattern moves unknown