Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw with Matplotlib

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to use Matplotlib drawing, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Today we will use real data to practice drawing with Matplotlib. Let's get started!

First, start, guide, and read the triple import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport warningswarnings.filterwarnings ("ignore") data = pd.read_csv ('sample data .csv'). Take a look at the data, that is, the oil prices of some countries in different years.

The next natural idea is to draw a line chart.

There seems to be something missing, by the way, add a title, and I don't know which line corresponds to which country in this picture, so I need another legend, in the same way as yesterday's article.

It seems that the picture is a little small, add a line of code to make it bigger.

What to do next? let's take a closer look at the X axis. Isn't it uncomfortable to see this year with a decimal point? change it!

Now the x-axis is finally a normal year, but there is a new problem. The X-axis is so crowded that I still feel bad. Instead, it shows a year every three years.

What do you do next? I always feel uncomfortable with this picture, and I want to show every point, so I'll change it again.

I feel much better. Hey, my x-axis and y-axis, arrange!

All right, it's almost done. I'm basically satisfied with getting up early. Now let's try to show data from all countries.

However, what is the automatically generated legend? change it, and there are so many countries that the legend will block the picture in the chart, so I have to fix it outside.

OK, get it done, finally save it, even if we finish our first Matplotlib assignment.

The great task has been completed! The above is to use a real data set to demonstrate the process of drawing a line chart using Matplotlib. Interested readers can click to read the original text to get the data (using a computer to obtain), but the source code is not given, and the source code in the text is also in the form of a screenshot. If you want to learn matplotlib thoroughly, you must type the code yourself, and you must make an error in the process of typing the code. Don't worry, Baidu / Google The first three search results are sure to solve your problem. On how to use Matplotlib drawing to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report