0% found this document useful (0 votes)
9 views

Matplot Axis Fig Level

plotting

Uploaded by

dmdkds87
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Matplot Axis Fig Level

plotting

Uploaded by

dmdkds87
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

In Matplotlib, figures and axes are fundamental objects that structure the way plots are created

and managed. Understanding the difference between figure level and axis level is crucial for
creating complex visualizations.

Figure Level

 Figure: The figure is the overall container that holds everything in the plot, including one
or more axes (subplots), titles, legends, and more. It can be thought of as the "canvas" on
which all elements of the plot are drawn.
 Figure-Level Commands: These commands affect the entire figure, such as setting the
size of the figure, adding titles, or saving the figure to a file.

Examples of figure-level commands:

o plt.figure(figsize=(width, height)): Creates a new figure and sets its size.


o fig.suptitle('Main Title'): Adds a title to the figure.
o fig.tight_layout(): Automatically adjusts subplot parameters to give specified
padding.
o fig.savefig('figure.png'): Saves the entire figure to a file.

python
Copy code
import matplotlib.pyplot as plt

# Create a figure with a specified size


fig = plt.figure(figsize=(10, 5))

# Add a title to the figure


fig.suptitle('Figure Level Title')

plt.show()

Axis Level

 Axes: An axes object represents an individual plot or graph. Each figure can contain
multiple axes (subplots), each with its own coordinate system, labels, titles, and data.
 Axis-Level Commands: These commands operate on individual axes, such as setting
labels, titles, or limits for a specific subplot.

Examples of axis-level commands:

o ax.set_title('Subplot Title'): Adds a title to the specific subplot.


o ax.set_xlabel('X Axis Label'): Sets the label for the x-axis.
o ax.set_ylabel('Y Axis Label'): Sets the label for the y-axis.
o ax.plot(x, y): Plots data on the specific axes.

python
Copy code
import matplotlib.pyplot as plt

# Create a figure
fig = plt.figure()

# Add a subplot (axes) to the figure


ax1 = fig.add_subplot(1, 2, 1) # 1 row, 2 columns, 1st subplot
ax2 = fig.add_subplot(1, 2, 2) # 1 row, 2 columns, 2nd subplot

# Plot on the first axes


ax1.plot([1, 2, 3], [4, 5, 6])
ax1.set_title('First Subplot')
ax1.set_xlabel('X Axis')
ax1.set_ylabel('Y Axis')

# Plot on the second axes


ax2.plot([1, 2, 3], [6, 5, 4])
ax2.set_title('Second Subplot')
ax2.set_xlabel('X Axis')
ax2.set_ylabel('Y Axis')

plt.show()

Key Points

 Figure is the entire plotting area or window, while axes is a single plot within that figure.
 Figure-level adjustments affect the overall appearance and layout, while axis-level
adjustments affect individual subplots.
 You can have multiple axes (subplots) within a single figure, each with its own data,
titles, labels, and limits.
 Use plt.figure() to create a new figure and fig.add_subplot() to add axes to that
figure.

Understanding and utilizing both figure-level and axis-level controls allows for the creation of
complex, well-organized visualizations in Matplotlib.

You might also like