Introduction
In this tutorial, we will learn how to create a simple axis line using Matplotlib in Python.
VM Tips
After the VM startup is done, click the top left corner to switch to the Notebook tab to access Jupyter Notebook for practice.
Sometimes, you may need to wait a few seconds for Jupyter Notebook to finish loading. The validation of operations cannot be automated because of limitations in Jupyter Notebook.
If you face issues during learning, feel free to ask Labby. Provide feedback after the session, and we will promptly resolve the problem for you.
Import Libraries
First, we need to import the necessary libraries.
import matplotlib.pyplot as plt
from mpl_toolkits.axisartist.axislines import Axes
Create Figure and Axes
Next, we will create a figure and axes object. We will use the add_subplot method to add the axes object.
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(axes_class=Axes)
Customize the Axes
We will now customize the axes by hiding the right and top axes lines.
ax.axis["right"].set_visible(False)
ax.axis["top"].set_visible(False)
Display the Plot
Finally, we can display the plot using the show method.
plt.show()
Summary
In this tutorial, we learned how to create a simple axis line using Matplotlib in Python. We imported the necessary libraries, created a figure and axes object, customized the axes, and displayed the plot.