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 understand the Python Visual Dash tool

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

Share

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

This article mainly introduces "how to understand Python visualization Dash tools". In daily operation, I believe many people have doubts about how to understand Python visualization Dash tools. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "how to understand Python Visualization Dash tools". Next, please follow the editor to study!

Dash is a Python visualization tool based on Flask. Strictly speaking, it consists of three parts: first, Flask provides a standard web environment, then plotly, a chart visualization tool, and finally, html, charts and other interactive components matched with dash. I have tried pyechart one after another, but in terms of integration and visualization, there is still a certain gap with dash.

Code example

Import dash-- Integrated flask import dash_core_components as dcc-- Core components related to diagrams import dash_html_components as html-- components related to HTML interactions-- import plotly.graph_objects as go-- underlying components of plotly-- import plotly.express as px-- High-level components of plotly The built-in dataset fig = go.Figure () fig = go.Figure (data=go.Bar (y = [2,3,1])) # fig.add_trace (...) # fig.update_layout (...) is also provided. Df = px.data.gapminder () df = px.data.gapminder (). Query ("country=='China'") fig = px.line (df, x = "year", y = "lifeExp", title=' population growth rate') app = dash.Dash () app.layout = html.Div ([dcc.Graph (figure=fig)]) app.run_server (debug=True, use_reloader=False)?

Plotly Express is an advanced encapsulation of Plotly.py with a large number of practical and modern drawing templates. Users can quickly generate beautiful interactive charts by calling simple API functions, which can meet more than 90% of application scenarios.

Plotly.express comes with built-in datasets for demonstration, educational, and testing purposes.

The data is stored in the package directory in CSV format, and the data is obtained by pandas type, which is convenient for chart function testing.

1. Gapminder (): each line represents a country's GDP, population growth, and other information in a given year. Contains 1704 lines and the following:

['country',' continent', 'year',' lifeExp', 'pop',' gdpPercap', 'iso_alpha',' iso_num'].

2. Tips (): each line represents a restaurant bill. Contains 244 lines and the following:

['total_bill',' tip', 'sex',' smoker', 'day',' time', 'size'].

3. Iris (): each row represents a flower. Contains 150 lines and the following:

['sepal_length',' sepal_width', 'petal_length',' petal_width', 'species',' species_id'].

4. Wind (): each line represents the wind intensity level and its frequency in a basic direction. Contains 128 lines and the following:

['direction',' strength', 'frequency'].

5. Election (): each row represents the voting results of a constituency in the 2013 Montreal mayoral election. Contains 58 lines and the following:

['district',' Coderre', 'Bergeron',' Joly', 'total',' winner', 'result',' district_id'].

6. Election_geojson (): each function represents a constituency in the 2013 Montreal mayoral election.

"dict" in GeoJSON format, with 58 polygons or polygons, its "id" is a selection number ID, and its' district' attribute is ID and region name.

7. Carshare (): each line indicates the availability of car sharing services near the regional center after a month in Montreal. Contains 249 lines and the following:

['centroid_lat',' centroid_lon', 'car_hours',' peak_hour'].

8. Stocks (indexed=False): each line in this broad data set represents the closing price of six technology stocks in 2018 / 2019. Contains 100 lines and the following:

['date',' GOOG', 'AAPL',' AMZN', 'FB',' NFLX', 'MSFT'].

9. Experiment (indexed=False): each row in this big data concentration represents the results of 100 simulated participants in three hypothetical experiments, as well as their gender and control / treatment group. Contains 100 lines and the following:

['experiment_1',' experiment_2', 'experiment_3',' gender', 'group'].

10. Medals_wide (indexed=False): this data set represents the Olympic short-track speed skating medal table of the top three countries by 2020. Contains 3 lines and the following:

['nation',' gold', 'silver',' bronze'].

11. Medals_long (indexed=False): this data set represents the Olympic short-track speed skating medal table of the top three countries by 2020. Contains 9 lines and the following:

['nation',' medal', 'count'].

Plotly.express provides more than 30 standard charts to simplify operations.

1. Scatter: in a scatter chart, each row of data_frame is represented by a symbol in 2D space.

2. Scatter_3d: in a 3D scatter chart, each row of data_frame is represented by a symbol in 3D space.

3. Scatter_polar: a polar scatter chart in which each row of data_frame is represented by symbols in polar coordinates

4. Scatter_ternary: in a ternary scatter chart, each row of data_frame is represented by a symbol in ternary coordinates

5. Scatter_mapbox: in a Mapbox scatter chart, each line of data_frame is represented by a symbol on the Mapbox map

6. Scatter_geo: a geographical coordinate scatter chart in which each line of data_frame is represented by a symbolic mark on the map

7. Line: in a 2D line graph, each line data_frame is represented as a vertex marked by a broken line in 2D space.

8. Line_3d: in a 3D graph, each row of data boxes is represented as the vertices marked by polylines in 3D space.

9. Line_polar: polar line graph in a polar chart, each line data_frame is represented as the vertex marked by a broken line in polar coordinates

10. Line_ternary: in a ternary line diagram, each line data_frame is represented as the vertex marked by a broken line in ternary coordinates

11. Line_mapbox: map line map in the Mapbox chart, each line data_frame is represented as the vertex marked by a broken line on the Mapbox map

12. Line_geo: geographical coordinate line map in a geographic line map, each line data_frame is represented as the vertex marked by a broken line on the map

13. Area: stacked area map in the stacked area map, each row of data_frame is represented as the vertices marked by broken lines in 2D space. The area between successive broken lines is filled.

14. Bar: in a bar chart, each row of data_frame is represented as a rectangular mark

15. Timeline: timeline Chart in the Timeline chart, each row of data boxes is represented as a rectangular marker on the x axis of the date type, starting with x and ending with x.

16. Bar_polar: a polar bar chart in which each row is represented by a data_frame as a wedge mark in polar coordinates

17. Violin: in a violin picture, each line of data_frame is marked with a curve to visualize their distribution.

18. Box: in a box diagram, each row of the data_frame is grouped together to form a box whisker mark to show their distribution

19. Strip: in a bar chart, each line of data_frame is represented as a jitter marker in a category

20. Histogram: in a histogram, each line of data_frame is grouped together into a rectangular marker to visualize the 1D distribution y (or x, if orientation is'h') of the aggregate function histfunc (for example, count or sum) of the value.

21. Pie: in the pie chart, each row of the data frame is represented as the sector of the pie chart.

22. Treemap: the tree view represents hierarchical data as nested rectangular sectors.

23. Sunburst: the circle chart represents hierarchical data as sectors arranged at multiple levels of concentric rings.

24. Funnel: in a funnel chart, each row of the data box is represented as a rectangular sector of the funnel.

25. Funnel_area: funnel area chart in the funnel area chart, each row of data boxes is represented as the trapezoidal sector of the funnel.

26. Scatter_matrix: Matrix scatter in the scatter matrix (or SPLOM), each row of data_frame is represented by multiple symbol markers, and there is one in each cell of the grid of the 2D scatter, which draws each pair of dimensions relative to each other.

27. Parallel_coordinates: parallel coordinate graph in a parallel coordinate graph, each row of data_frame is represented by a broken line mark, which passes through a set of parallel axes, each parallel axis corresponding to a parallel axis dimensions

28. Parallel_categories: in a parallel category (or parallel set) diagram, each row data_frame is combined with other rows that share the same value, and the dimensions is then drawn as a dotted mark through a set of parallel axes, with each parallel axis corresponding to a dimensions

29. Choropleth: contour (value) area map in the equivalent area map, each row of data_frame is represented by a color area mark on the map

30. Choropleth_mapbox: in a Mapbox choropleth map, the data of each row is represented by a colored area on the Mapbox map.

31. Density_contour: density isoline map (bivariate distribution) in a density isoline map, rows data_frame are grouped together to form contour markers to visualize the 2D distribution z of the aggregate function histfunc (for example: count or sum) of the value

32. Density_heatmap: density thermal map (bivariate distribution) in a density heat map, rows of data_frame are grouped together to form colored rectangular tiles to visualize the 2D distribution z of the aggregate function histfunc (for example, counting or summation) of this value.

33. Density_mapbox:Mapbox density map in the Mapbox density map, each row of data frames will affect the color intensity of the area around the corresponding point on the map.

Plotly.graph_objects is the underlying component, which provides figures, traces and layout and other underlying interfaces for flexible development.

Figure container

Layout layout

Simple Traces simple trajectory

Distribution Traces distribution trajectory

Finance Traces financial track line

Map Traces map track line

Specialized Traces special trajectory

The dash_html_ elements library contains the component classes for each HTML tag and the keyword parameters for all HTML parameters.

There are several important differences between the dash_html_components and HTML properties:

1. In HTML, the style attribute is a semicolon-delimited string. In Dash, you can use a dictionary.

2. The key value in style dictionary is cameCase (hump style), not text-align, but textAlign.

3. The HTML class attribute is the className in Dash.

4. The children of the HTML tag are specified by the children keyword parameter.

The dash_core_ implementations library contains a higher-level set of components, such as drop-down lists, graphics, and so on.

The dash_html_ tags library provides classes for all HTML tags, while keyword parameters describe HTML attributes, such as style,className and ID.

The dash_core_ implementations library generates high-level components, such as controls and graphics.

At this point, the study on "how to understand Python Visualization Dash tool" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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