In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the methods of making cool Python dynamic diagrams". In daily operation, I believe that many people have doubts about the methods of making cool Python dynamic diagrams. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions of "what are the methods of making cool Python dynamic diagrams?" Next, please follow the editor to study!
1. Chaoyang map
Hierarchical data is usually stored as a rectangular data box, where different columns correspond to different levels of the hierarchy. Px.sunburst can take the parameters that path corresponds to the column list. Note that if id is given, parent should not provide path.
Import plotly.express as px df = px.data.tips () fig = px.sunburst (df, path= ['day',' time', 'sex'], values='total_bill') fig.show ()
two。 Sanji diagram
Sanji graph represents the source node by defining the contribution source that is visualized to the flow, the target is the target node, the numerical value is to set the flow volum, and the label, and displays the node name, which is commonly used in traffic analysis.
Import plotly.graph_objects as go import urllib, json url = 'https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/sankey_energy.json' response = urllib.request.urlopen (url) data = json.loads (response.read ()) # override gray link colors with' source' colors opacity = 0.4 # change 'magenta' to its' rgba' value to add opacity data ['data'] [0] [' node'] ['color'] = [' rgba If color = "magenta" else color for color in data ['data'] [0] [' node'] ['color']] data [' data'] [0] ['link'] [' color'] = [data ['data'] [0] [' node'] ['color'] [src] .replace Str (opacity) for src in data ['data'] [0] [' link'] ['source']] fig = go.Figure (data= [go.Sankey (valueformat = ".0f", valuesuffix = "TWh", # Define nodes node = dict (pad = 15, thickness = 15, line = dict (color = "black", width = 0.5) Label = data ['data'] [0] [' node'] ['label'], color = data [' data'] [0] ['node'] [' color']), # Add links link = dict (source = data ['data'] [0] [' link'] ['source'], target = data [' data'] [0] ['link'] [' target']) Value = data ['data'] [0] [' link'] ['value'], label = data [' data'] [0] ['link'] [' label'], color = data ['data'] [0] [' link'] ['color'])] fig.update_layout (title_text= "Energy forecast for 2050
Source: Department of Energy & Climate Change, Tom Counsell via Mike Bostock ", font_size=10) fig.show ()
Effect picture
3. Radar chart
A radar map (also known as a spider plot or plot star) displays multivariable data in the form of a two-dimensional graph representing quantitative variables originating from the central axis. The relative position and angle of the axis are usually useless. It is equivalent to a parallel coordinate diagram arranged along the radial axis.
Import plotly.graph_objects as go import urllib, json url = 'https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/sankey_energy.json' response = urllib.request.urlopen (url) data = json.loads (response.read ()) # override gray link colors with' source' colors opacity = 0.4 # change 'magenta' to its' rgba' value to add opacity data ['data'] [0] [' node'] ['color'] = [' rgba If color = "magenta" else color for color in data ['data'] [0] [' node'] ['color']] data [' data'] [0] ['link'] [' color'] = [data ['data'] [0] [' node'] ['color'] [src] .replace Str (opacity) for src in data ['data'] [0] [' link'] ['source']] fig = go.Figure (data= [go.Sankey (valueformat = ".0f", valuesuffix = "TWh", # Define nodes node = dict (pad = 15, thickness = 15, line = dict (color = "black", width = 0.5) Label = data ['data'] [0] [' node'] ['label'], color = data [' data'] [0] ['node'] [' color']), # Add links link = dict (source = data ['data'] [0] [' link'] ['source'], target = data [' data'] [0] ['link'] [' target']) Value = data ['data'] [0] [' link'] ['value'], label = data [' data'] [0] ['link'] [' label'], color = data ['data'] [0] [' link'] ['color'])] fig.update_layout (title_text= "Energy forecast for 2050
Source: Department of Energy & Climate Change, Tom Counsell via Mike Bostock ", font_size=10) fig.show ()
Effect picture
4. Funnel chart
Funnel charts are often used to represent data at different stages of a business process. In business intelligence, this is an important mechanism for identifying potential problem areas of the process. For example, it is used to observe revenue or loss at each stage of the sales process and to display diminishing values. Each stage is expressed as a percentage of all values.
From plotly import graph_objects as go fig = go.Figure () fig.add_trace (go.Funnel (name = 'Montreal', y = ["Website visit", "Downloads", "Potential customers", "Requested price"], x = [120,60,30,20], textinfo = "value+percent initial") fig.add_trace (go.Funnel (name =' Toronto', orientation = "h", y = ["Website visit", "Downloads") "Potential customers", "Requested price", "invoice sent"], x = [100,60,40,30,20], textposition = "inside", textinfo = "value+percent previous") fig.add_trace (name = 'Vancouver', orientation = "h", y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent", "Finalized"], x = [90,70,50,30) 10, 5], textposition = "outside", textinfo = "value+percent total") fig.show ()
Effect picture
5. 3D surface view
Surface views with outlines, use the contours property to display and customize the outline data for each axis.
Import plotly.graph_objects as go import pandas as pd # Read data from a csv z_data = pd.read_csv ('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv') fig = go.Figure (data= [go. Surface (z=z_data.values)]) fig.update_traces (contours_z=dict (show=True, usecolormap=True, highlightcolor= "limegreen") Project_z=True)) fig.update_layout (title='Mt Bruno Elevation', autosize=False, scene_camera_eye=dict (x = 1.87, y = 0.88, zonal color 0.64), width=500, height=500, margin=dict (lump 65, rust 50, bang 65, tween 90)) fig.show ()
6. Animated drawing
Some Plotly Express functions support the creation of animated characters with animation_frame and animation_group parameters. This is an example of an animated scatter chart created using Plotly Express. Note that you should always fix x_range and y_range to ensure that your data is always visible throughout the animation.
Import plotly.express as px df = px.data.gapminder () px.scatter (df, x = "gdpPercap", y = "lifeExp", animation_frame= "year", animation_group= "country", size= "pop", color= "continent", hover_name= "country", log_x=True, size_max=55, range_x= [100jue 100000], range_y= [25recover90]). This is the end of the study on "what are the methods of making dynamic diagrams of cool Python?" I hope I can solve everyone's 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.
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.