In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to draw Matplotlib, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Matplotlib is the basic package of visualization in Python, it can easily draw two-dimensional and three-dimensional charts, and the drawing style is close to MATLAB, so it is called matplotlib. Beautiful graphics can be drawn with simple statements. In this article, we will learn about the constituent elements of matplotlib diagrams. Some common drawing components and concepts have been shown in the diagram at the beginning of the article. The diagram can be drawn using a simple API. Combined with graphics, we first explain some concepts and basic API, and finally use the complete code to draw this picture. The background replies to "drawing" to get the complete code of this article.
Basic concept
As the graph shows, when we operate on matplotlib, we start with Figure, which is often called canvas, similar to the artboard when drawing in real life. On the drawing board, we can draw one or more graphics, which are called axes. All graphic elements, such as axes, ticks, labels, lines, tags, etc., are on top of the graphic instance. When there is only one instance of axes, we can use matplotlib.pyplot to manipulate these graphical elements to "make up" a complete picture.
How to use common chart elements
Before drawing, we need to import the corresponding package: pyplot is used to manipulate chart elements, and numpy is used to generate the basic data needed for drawing.
Import matplotlib.pyplot as pltimport numpy as np
The use of chart elements is basically accomplished by calling the function of plt, and setting the corresponding parameters can produce different effects. Some common functions are summarized as follows:
Let's take a look at a simple example, with the code and effect shown below:
In this example, almost all of the functions listed above are used. Y is the sine function of x, the effect of the above code is: draw a linetype relationship between y and x, add a note with arrowhead at the highest point, add a note without arrowhead next to the line, draw a horizontal dashed line, label the x-axis label, y-axis label, set the Abscissa range, and finally add the title and legend.
Draw the picture at the beginning of the article
Next, we will further use the above function to draw the graph at the beginning of the article. Spine,ticklabel,tickline and other elements are added in the figure, and each element is explained mainly through directed and undirected comments, which is not only easy to understand and consult, but also can further deepen the understanding of matplotlib by learning the following code. The code and comments are as follows:
Run the above code to draw this picture. It is important to note that annotate comments can only be made within axes, while the text () function can write comments "anywhere".
The above is all the content of this article "how to draw Matplotlib". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.