Programming with Ai Wenwen "Zero-Basic Getting Started with Python" (01) Dynamic Visual Drawing Based on Plotly

Author: Ai Wen, a master's degree in computer science, an in-house training lecturer and a gold medal interviewer, a senior algorithm expert in the company, and now working in a BAT first-tier factory.
E-mail: [email protected]
Blog: https://wenjie.blog.csdn.net/
Content: Programming with Ai Wenjie "Learning Python with Zero Basics"

Target

  • Introduction to basic concepts of plotly
  • Introduction to plotly drawing control
  • plotly install
  • Draw a plotly graph visualization
  • Visualization charts (histograms, histograms, scatterplots, pie charts, heat maps, timing diagrams, boxplots, etc.)

content

  • introduce¶

Based on Python for data analysis, Matplotlib has shortcomings such as not beautiful enough, static, and difficult to share, which limits the development of Python in data visualization. In order to solve this problem, Plotly, a new dynamic visualization open source module, came into being. Because Plotly has the characteristics of dynamic, beautiful, easy to use, and rich in types. Project cases include Titanic data, iris data, flight data, and financial data for visual chart analysis, which can quickly let everyone know how to deal with data analysis in the project.

Project actual content: Titanic data, iris data, flight data, financial data

  • Require

Whether you are a zero-based person or a student with a certain Python foundation, you can learn through this course. The focus of this course is based on practical tutorials, allowing you to quickly master the use of Python tools and how to conduct data analysis through jupyter-notebook. The real business understanding can be analyzed through the interactive graph plotly. These courses are also very helpful especially for AI product managers. This course can make you faster, more efficient and get the most out of your work in the company's data analysis.

  • benefit from

Quickly master how to use the Plotly library, and skillfully draw common charts in various data analysis

Master the method of python data analysis

Introduction to plotly

python drawing: matplotlib, seaborn, plotly

One business scenario of data analysis is to use data to tell stories, and tools for interactive information visualization highlight the advantages here.

There are still many Python visualization libraries. Mastering matplotlib and seaborn well, using plotly for specific businesses is enough to calmly face most data analysis scenarios.

Plotly is a very famous and powerful open source data visualization framework. It displays information by building interactive web-based charts based on browser displays, and can create dozens of beautiful charts and maps.

Below we use jupyter notebook as a development tool for data analysis. Matplotlib has shortcomings such as not beautiful enough, static, and not easy to share, which limits the development of Python in data visualization. In order to solve this problem, Plotly, a new dynamic visualization open source module, came into being.

Because Plotly has the characteristics of dynamic, beautiful, easy to use, and rich in types.

It can be said that plotly is a top-level drawing method when drawing charts in Python.

Let's first take a look at the data visualization renderings through the plotly official website. Here we intercept a part of the effect and find that it is extremely powerful, and it also supports online editing of data/pictures.

plotly drawing control

Basic charts: 20 types

Statistical and Shipping Way Map: 12 Types

Scientific charts: 21 types

Financial charts: 2 types

Maps: 8 types

3D charts: 19 types

Report generation: 4 types

Connection database: 7 types

Fitting tools: 3 types

Flow chart: 4 types

JavaScript to add custom controls: 13 types

plotly install

pip install plotly

After completing the ploytly installation Chengxiu, we need to check whether it is installed, through the following operations

The first plotly graph visualization

  • Import related packages

  • the first to draw the graph

The display results are as follows

Visual chart data case

The data of all project cases in this course include: Titanic data, iris data, flight data, and financial data. Through the analysis of these data, you can quickly let everyone master the plotly in the project for data drawing analysis.

  • Download Data

  • View 4 types of data (default 5)

Here flights are processed by the pivot function

Financial data display

Project Case 1: Titanic Histogram

When analyzing a set of data, what you look at is the distribution of variables, and the histogram provides such a very simple function.

By observing the data, display the histogram of the age. The actual age data has missing data. First use the dropna function to delete the missing data, otherwise the graph cannot be drawn.

Project Case 2: Titanic Histogram

Here we count the number of surviving people corresponding to each type of position level data analysis

Project case 3: Titanic grouped histogram

Our x-axis position level class, we will refine the sex to complete the effect of the grouped histogram

Project case 4: iris scatterplot

Scatterplot: It is mainly used to analyze the concentration of data.

Project Case 5: Line Chart of Flight Data

Mainly analyze some changing trends of the data. Here we analyze the flight data, mainly looking at some changes in the number of passengers every year and every month

The above operation is very troublesome. Define a function to encapsulate the data of each year, and then all the data can be displayed

Project Case 6: Titanic Pie Chart

Through the pie chart, it is mainly used to analyze the proportion of different categories of data

Analyze the proportion of survivors of different embarked personnel

Project Case 7: Boxplot of the Titanic

It is a function and data analysis whether it is abnormal point data or outlier point. It can display the maximum value, minimum value, median and upper and lower quartile data of a set of data. This data can be observed through this graph

We count the age distribution of different position levels

We can further optimize and adjust our above code to make our code easier to view and the amount of code is relatively small

Project Case 8: Heat Map of Flight Data

It is usually used to indicate the correlation between features, and the depth of the color is generally used to indicate the size of the value or the level of correlation

Let's first use a simple data example to observe how to generate a heat map, focusing on building the data of the three variables x, y, and z

Next, we load the data of one of our flights through pandas, the number of passengers per month per year, which is a practical application of a heat map

What we need to build a heat map is three-dimensional data information

x: month label

y: year label

z: the number of passengers corresponding to the year and month

Project Case 9: Financial Data Sequence Diagram

We can change the data at each time point through the timing diagram, for example: In the financial field, this method can be used to analyze the daily stock price trend

Statistics on the daily stock price trend of financial data

Next, we are further optimizing the function

For more content learning, please pay attention, comment more and support more, let us work together.

Guess you like

Origin blog.csdn.net/shenfuli/article/details/127958762