Line With Text

Beginner

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

Introduction

This lab demonstrates how to override basic methods so an artist can contain another artist in Python Matplotlib.

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.

Summary

This lab demonstrated how to override basic methods so an artist can contain another artist in Python Matplotlib. We created a custom class called MyLine which inherited from lines.Line2D and contained a mtext.Text instance to label it. We then added the line to an axis object and displayed the plot.

Other Tutorials you may like