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 realize Python data Visualization Pyecharts Library to realize Mulberry Chart effect

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to achieve Python data visualization Pyecharts library to achieve mulberry map effect", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to achieve Python data visualization Pyecharts library to achieve mulberry map effect" bar!

Catalogue

I summarize that there are about three steps in the basic idea:

1. Declare the use of sankey first

two。 Use add to add configuration information for sankey diagrams

3. Finally, render generates a html file for display.

First of all, what is the mulberry map?

Sankey diagram, that is, Sanji energy shunt diagram, also known as Sanji energy balance diagram.

It is a specific type of flow chart, in which the width of the extended branches corresponds to the size of data flow, which is usually used in the visual analysis of energy, material composition, finance and other data.

It is famous for the Energy efficiency Chart of the Steam engine drawn by Matthew Henry Phineas Riall Sankey in 1898 and has since been named Sanji Tu.

Grasping the core definition of mulberry diagram is the process of expressing a data stream in the main terms. In fact, we are familiar with the Matplotlib can also draw mulberry picture, but does it look a little bit ugly? As follows:

This article uses another commonly used visualization library, pyecharts, to draw pictures.

It needs to be emphasized here that pyecharts is divided into two major versions, v0.5.x and v1, and the two versions are incompatible. V 0.5.x supports python2.7 and 3.4 +, while v1 initially supports only python 3.6 +, which is officially divided into two different documents.

There are also many materials and learning examples for v1 on the Internet. This article provides help for students who are still using the version of v 0.5.x. The examples later in this article use the v 0.5.x version. Official document

First use the familiar pip for installation

Pip install pyecharts

Then we can learn against the introduction of API in the official documentation, and we need to introduce Sankey.

The core parameters are different, mainly due to the configuration of some display of the mulberry chart.

I summed up the basic ideas in about three steps: 1. First declare the use of sankeysankey = Sankey ("Sanji diagram example", width=1200, height=600) 2. Use add to add configuration information for sankey diagrams sankey.add ("sankey", nodes=j ["nodes"], links=j ["links"], line_opacity=0.2, line_curve=0.5, line_color= "source", is_label_show=True, label_pos= "right",)

It should be noted here that nodes and links are required parameters, which are equivalent to the nodes and connected edges in the mulberry diagram. You need to pass in an List data with an embedded dictionary data format, as shown below. The name, source, target and value here are all fixed.

Nodes = [{'name':' category1'}, {'name':' category2'}, {'name':' category3'}, {'name':' category4'}, {'name':' category5'}, {'name':' category6'},] links = [{'source':' category1', 'target':' category2', 'value': 10}, {' source': 'category2' Target': 'category3',' value': 15}, {'source':' category3', 'target':' category4', 'value': 20}, {' source': 'category5',' target': 'category6',' value': 25}] 3. Finally, render generates a html file to show sankey.render ()

Finally, I would like to share with you a small example:

Def sankey_analysis (): nodes = [{'name':'Cluster 1'}, {'name':'Cluster 2'}, {'name':'Cluster 3'}, {' name':'Young'}, {'name':'Medium'}, {' name':'Elder'}] result = np.array ([[130151188], [735462670]) [711625881]]) targets = ['Young',' Medium' 'Elder'] links = [] for i in range (0Power3): for j in range (0Magne3): sub_dict = {} sub_dict [' source'] = 'Cluster' + str (item1) sub_dict ['target'] = targets [j] sub_dict [' value'] = result [I J] links.append (sub_dict) pic = (Sankey (name, width=1200, height=600) .add (', nodes, links, sankey_node_width=80, sankey_node_gap=5, line_opacity=0.7, line_curve=0.5, line_color='source', is_label_show=True, is_random = True Label_text_size=14, label_pos= "inside")) pic.render ('sankey.html')

Thank you for reading, the above is "how to achieve Python data visualization Pyecharts library to achieve mulberry map effect" content, after the study of this article, I believe you on how to achieve Python data visualization Pyecharts library to achieve mulberry map effect of this problem has a deeper understanding, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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