Introduction to legends, titles and labels of the python-based 2D image gallery Matplotlib

爱喝马黛茶的安东尼
Release: 2019-06-04 14:18:28
forward
3277 people have browsed it

Matplotlib is a Python 2D plotting library that can produce publication-quality graphics in a variety of hardcopy formats and interactive environments on a variety of platforms.

Introduction to legends, titles and labels of the python-based 2D image gallery Matplotlib

In the previous article we explained How to install the Matplotlib library. In this tutorial, we will discuss the legend, title and label in Matplotlib. Many times, graphs can be self-explanatory, but it is essential that the graph has a title, labels on the axes, and a legend to explain what each row is.

Note: Axes is the area surrounded by two coordinate axes.

Start here:

import matplotlib.pyplot as plt
x = [1,2,3]
y = [5,7,4]
x2 = [1,2,3]
y2 = [10,14,12]
Copy after login

So we can draw two lines, next:

plt.plot(x, y, label='First Line')
plt.plot(x2, y2, label='Second Line')
Copy after login

Here we draw what we have already seen stuff, but this time we add another parameter label. This allows us to give the line a name, which we can later display in the legend. The rest of our code is:

plt.xlabel('Plot Number')
plt.ylabel('Important var')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
plt.show()
Copy after login

Using plt.xlabel and plt.ylabel we can create labels for these corresponding axes. Next, we can use plt.title to create a title for the figure, and then we can use plt.legend() to generate a default legend. The results are as follows:

Introduction to legends, titles and labels of the python-based 2D image gallery Matplotlib

The above is the detailed content of Introduction to legends, titles and labels of the python-based 2D image gallery Matplotlib. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!