In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to draw Python Sanji diagram, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Preface
Sanji chart, also known as Sanji energy shunt chart and Sanji energy balance chart, is a specific type of flow chart, which is used to show the "flow" changes of data. The Sanji graph contains several branches extending from left to right, and the width of each branch represents the size of the data flow.
Topic reproduction
Suppose that the daily expenses of Xiaoming's family are mainly divided into salary, sideline, life, shopping, further study, sports, other and buying books, and each input or output value is 0.7, 0.3,-0.3,-0.1,-0.3,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1,-0.1
Problem disassembly
We need to draw the Sangji diagram. First of all, we know that the class Sankey that represents the Sangji diagram is specially mentioned in the class. Matplotlib.sankey module. By creating the object of the Sankey class, we can create the Sangji diagram, and then we can call the add () method to add some configuration options for the Sankey diagram. Finally, we can call the finish () method to complete the drawing of the Sangji diagram.
Create a Sanji diagram Sankey (ax=None, scale=1.0,unit='',format='%G',gap=0.25,radius=0.1,shoulder=0.03,offset=0.15,head_angle=100,margin=0.4,tolerance=1e-06,**kwargs)
The common function parameters are as follows:
Ax: if this parameter is not provided, a new axis will be created
Scale: a factor that represents the proportion of traffic, which is used to adjust the width of the branch proportionally
Unit: a string that represents the physical unit associated with traffic. If set to None, no quantity mark will be made.
Gap: indicates the distance between branches entering or leaving the top or bottom. The default is 0.25.
Add Sanji Chart option
Sankey class objects can call the add () method to add options such as data flow, labels, etc., to the Sanji diagram.
Add (self,patchlabel='',flows=None,orientations=None,labels='',trunklength=1.0, pathlengths=0.25,prior=None,connect= (0d0), rotation=0,**kwargs)
The common parameters are as follows:
Patchlabel: represents the label at the center of the chart
Flows: indicates an array of traffic data, in which the input data is positive and the resulting data is negative.
Orientations: represents a list of directions for a stream or a single direction for all streams. Values can be 0 (input from the left, output from the right), 1 (from top to top) or-1 (from bottom to bottom)
Labels: represents a list of tags for streams or a single label for all streams
Trunklength: indicates the length between the bases of the input group and the output group
Returns the object drawn by the Sanji diagram
After adding data, the Sankey class object needs to call the finish () method to complete the drawing and return a list of multiple mulberry subgraphs, which contain the following fields.
Patch: represents the outline of the Sangji subgraph
Flows: indicates the traffic value (positive input, negative output)
Angles: a list of arrowhead angles
Tips: an array that represents the tip or depression of a flow path, where each row is one (xmemy)
Text: an instance of Text that represents the central label
Texts: an Text instance that represents the flow branch label
3. Complete source code if _ _ name__ ='_ main__': import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib.sankey import Sankey plt.rcParams ['font.sans-serif'] =' SimHei' plt.rcParams ['axes.unicode_minus'] = False # consumption income and Expenditure data flows = [0.7,0.3 meme 0.3qili 0.1qiang 0.1qiang 0.1qin -0.1] # tag list of the stream labels = ["salary", "sideline", "life", "shopping", "further study", "sports", "other", "buying books"] # the direction of the stream orientations = [1je 1m 0m 1m 1m 0] # create a Sankey class object sankey = Sankey () sankey.add (flows=flows, # income and expenditure data labels = labels # data label orientations = orientations, # direction displayed by the label color='black', # Edge line color fc= "lightgreen", # fill color patchlabel= "living consumption" # Chart Chinese Heart label alpha=0.7) # Sangji drawing completed object diagrams = sankey.finish () diagrams [0] .picture [4] .set _ color ("r") # set the data label with subscript 4 to red diagrams [0] .label [4] .set _ weight ("bold") # set the data label with subscript 4 to font Tag diagrams [0] .text.set _ fontsize (20) # sets the font size of the center tag to 20 diagrams [0] .text.set _ fontweight ("bold") # sets the font of the center tag to bold plt.title ('Sanji Map of Daily living expenses') plt.show () above is all the content of the article "how to draw Sanji Diagram by Python" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.