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

What is the drawing principle of the four commonly used drawing libraries in Python

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "what is the drawing principle of the four commonly used drawing libraries of Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. The principle of matplotlib drawing

For more detailed drawing instructions on matplotlib, you can refer to the following article. I'm sure you'll learn it after reading it.

Principle of matplotlib drawing: http://suo.im/678FCo

1) explanation of drawing principle

Through my own study and understanding, I highly summarize the principle of matplotlib drawing into the following steps:

① import library

② creates figure canvas object

③ gets the axes coordinate system object of the corresponding position

④ calls the axes object to draw the corresponding position.

⑤ display graphics

2) case description

# 1. Import related library import matplotlib as mpl import matplotlib.pyplot as plt # 2. Create the figure canvas object figure = plt.figure () # 3. Get the axes coordinate system object axes1 = figure.add_subplot (2Magi 1) axes2 = figure.add_subplot (2 Magi 1 Magi 2) # 4. Call the axes object to draw the graphics of the corresponding position axes1.plot ([1, 3, 5, 5, 7], [4, 9, 6, 8]) axes2.plot ([1, 2, 4, 4, 5])) # 5. Show graphic figure.show ()

The results are as follows:

2. The principle of seaborn drawing

In these four drawing libraries, only matplotlib and seaborn have a certain relationship, and there is no relationship between other drawing libraries, even the drawing principles are not the same.

Seaborn is a more advanced encapsulation of matplotlib. Therefore, before learning seaborn, we must first know the drawing principle of matplotlib. Because seaborn is a more advanced encapsulation of matplotlib, those tuning parameter settings for matplotlib can also be used after drawing with seaborn.

We know that using matplotlib to draw requires adjusting a large number of drawing parameters and memorizing a lot of things. On the other hand, seaborn makes a more advanced encapsulation based on matplotlib, which makes it easier to draw. It does not need to know a lot of underlying parameters to draw a lot of more exquisite graphics. Not only that, seaborn is also compatible with numpy and pandas data structures, which plays an important role in organizing data, thus helping us to complete data visualization to a greater extent.

As the drawing principle of seaborn is consistent with that of matplotlib, it will not be introduced in detail here. You can refer to the drawing principle of matplotlib above to learn how to draw seaborn. Here, we still provide a web site for you.

Principle of seaborn drawing: http://suo.im/5D3VPX

1) case description

# 1. Import the related library import seaborn as sns import matplotlib.pyplot as plt df = pd.read_excel ("data.xlsx", sheet_name= "data source") sns.set_style ("dark") plt.rcParams ["font.sans-serif"] = ["SimHei"] plt.rcParams ["axes.unicode_minus"] = False # Note: estimator represents the sum of the grouped sales quantity. The default is to find the average. Sns.barplot (x = "brand", y = "sales quantity", data=df,color= "steelblue", orient= "v", estimator=sum) plt.show ()

The results are as follows:

Note: you can see that in the above drawing code, you should have such a feeling that there is both matplotlib drawing code and seaborn drawing code. In fact, it is like this, we are in accordance with the principle of matplobt drawing graphics, but some places can be changed to seaborn-specific code, the rest of the adjustment format, can be adjusted using the method in matplotlib.

3. The principle of plotly drawing

First of all, before introducing the drawing principle of this diagram, let's briefly introduce plotly as a drawing library.

Plotly is a drawing library based on javascript. Plotly has a wide variety of drawings and beautiful effects.

Easy to save and share plotly drawing results, and can be seamlessly integrated with Web

The default drawing result of ploty is a HTML web page file, which can be viewed directly through the browser.

Its drawing principle has nothing to do with matplotlib or seaborn, you need to learn it alone. Similarly, I still provide a website for you to learn plotly in more detail.

Principle of plotly drawing: http://suo.im/5vxNTu

1) explanation of drawing principle

Through my own study and understanding, I highly summarize the principle of plotly drawing into the following steps:

① draws graphical tracks, which are called trace in ployly, and each track is a trace.

② wraps tracks into a list to form a "track list". A track is placed in a list, and multiple tracks are also placed in a list.

When ③ creates the canvas, he passes the above track list into Figure ().

④ uses Layout () to add additional drawing parameters to refine the graph.

⑤ displays graphics.

2) case description

Import numpy as np import pandas as pd import plotly as py import plotly.graph_objs as go import plotly.expression as px from plotly import tools df = pd.read_excel ("plot.xlsx") # 1. Draw graphical tracks, which are called `trace` in ployly, and each track is a trace. Trace0 = go.Scatter (x=df ["year"], y=df ["urban resident"], name= "urban resident") trace1 = go.Scatter (x=df ["year"], y=df ["rural resident"], name= "rural resident") # 2. Wrap the tracks into a list to form a "track list". A track is placed in a list, and multiple tracks are also placed in a list. Data = [trace0,trace1] # 3. When creating the canvas, pass the above `track list `to `track ()`. Fig = go.Figure (data) # 4. Use `drawing () `to add other drawing parameters to improve the graphics. Fig.update_layout (title= "per capita income of urban and rural households", xaxis_title= "year", yaxis_title= "per capita income (yuan)") # 5. Show the graphics. Fig.show ()

The results are as follows:

4. The principle of pyecharts drawing

Echarts is an open source data visualization tool by Baidu. With its good interaction and exquisite chart design, it has been recognized by many developers. Python is an expressive language, which is very suitable for data processing. When data analysis meets data visualization, pyecharts is born.

Pyecharts is divided into v0.5 and v1 two major versions, v0.5 and v1 are not compatible, v1 is a new version, so our learning is based on v1 version as far as possible.

Like plotly, the drawing principle of pyecharts is completely different from that of matplotlib and seaborn. We need to learn extra about their drawing principles. Based on this, we also provide you with a website to learn pyecharts in more detail.

The drawing principle of pyecharts: http://suo.im/5S1PF1

1) explanation of drawing principle

Through my own study and understanding, I highly summarize the principle of plotly drawing into the following steps:

① Select Chart Type

② declares graphics classes and adds data

③ selects global variables

④ display and save charts

2) case description

# 1. Select the chart type: we use a line graph and import the Line module directly from the charts module; from pyecharts.charts import Line import pyecharts.options as opts import numpy as np x = np.linspace (0mem2 * np.pi,100) y = np.sin (x) (# 2. We are drawing a line diagram, so we need to instantiate this graph class, just Line () directly; Line () # 3. Add data, add data to the x _ ray y-axis respectively .add _ xaxis (xaxis_data=x) .add _ yaxis (series_name= "drawing Line Graph", yearly axisymmetric https://www.baidu.com/"), labeloptsLabelOpts (is_show=False)) .set _ global_opts (title= "I am the title", subtitle= "I am the subtitle", title_link= "subtitle") Tooltip_opts=opts.TooltipOpts ()) .render_notebook () # 4.render_notebook () is used to display and save charts

The results are as follows:

This is the end of the introduction of "what are the drawing principles of the four commonly used drawing libraries in Python". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Development

Wechat

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

12
Report