Matplotlib Simple Axisline3

MatplotlibMatplotlibBeginner
Practice Now

This tutorial is from open-source community. Access the source code

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.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL matplotlib(("`Matplotlib`")) -.-> matplotlib/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"]) python(("`Python`")) -.-> python/DataScienceandMachineLearningGroup(["`Data Science and Machine Learning`"]) matplotlib/BasicConceptsGroup -.-> matplotlib/importing_matplotlib("`Importing Matplotlib`") matplotlib/BasicConceptsGroup -.-> matplotlib/figures_axes("`Understanding Figures and Axes`") python/BasicConceptsGroup -.-> python/booleans("`Booleans`") python/DataStructuresGroup -.-> python/lists("`Lists`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/ModulesandPackagesGroup -.-> python/importing_modules("`Importing Modules`") python/ModulesandPackagesGroup -.-> python/using_packages("`Using Packages`") python/DataScienceandMachineLearningGroup -.-> python/data_visualization("`Data Visualization`") subgraph Lab Skills matplotlib/importing_matplotlib -.-> lab-48938{{"`Matplotlib Simple Axisline3`"}} matplotlib/figures_axes -.-> lab-48938{{"`Matplotlib Simple Axisline3`"}} python/booleans -.-> lab-48938{{"`Matplotlib Simple Axisline3`"}} python/lists -.-> lab-48938{{"`Matplotlib Simple Axisline3`"}} python/tuples -.-> lab-48938{{"`Matplotlib Simple Axisline3`"}} python/importing_modules -.-> lab-48938{{"`Matplotlib Simple Axisline3`"}} python/using_packages -.-> lab-48938{{"`Matplotlib Simple Axisline3`"}} python/data_visualization -.-> lab-48938{{"`Matplotlib Simple Axisline3`"}} end

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.

Other Matplotlib Tutorials you may like