OwlCyberSecurity - MANAGER
Edit File: sankey.cpython-38.pyc
U ��]�� � @ s� d Z ddlZddlmZ ddlZddlmZ ddlm Z ddl mZ ddlm Z ddlmZ e�e�Zd Zd gZdZdZdZd ZdZG dd� de�ZdS )z7 Module for creating Sankey diagrams using Matplotlib. � N)�SimpleNamespace)�Path)� PathPatch)�Affine2D)� docstring)�rcParamszKevin L. Daviesz Yannick CopinZBSDz 2011/09/16� � c @ sZ e Zd ZdZdd d�Zd dd�Zdd� Zdd� Zej fdd�Z ejd!dd��Z dd� ZdS )"�Sankeyab Sankey diagram. Sankey diagrams are a specific type of flow diagram, in which the width of the arrows is shown proportionally to the flow quantity. They are typically used to visualize energy or material or cost transfers between processes. `Wikipedia (6/1/2011) <https://en.wikipedia.org/wiki/Sankey_diagram>`_ N� �?� �%G� �?皙�����?���Q��?�333333�?�d 皙�����?���ư>c K s |dk rt d��||kr t d��| dk r0t d��|dk r@t d��|dkrpddlm} | �� }|jdddg g d�}g | _|| _|| _|| _|| _ || _ || _|| _|| _ | | _t�tjd| d d �| _|| _t�tjtj tjtj f�| _t|��r| jf |� dS )aH Create a new Sankey instance. Optional keyword arguments: =============== =================================================== Field Description =============== =================================================== *ax* axes onto which the data should be plotted If *ax* isn't provided, new axes will be created. *scale* scaling factor for the flows *scale* sizes the width of the paths in order to maintain proper layout. The same scale is applied to all subdiagrams. The value should be chosen such that the product of the scale and the sum of the inputs is approximately 1.0 (and the product of the scale and the sum of the outputs is approximately -1.0). *unit* string representing the physical unit associated with the flow quantities If *unit* is None, then none of the quantities are labeled. *format* a Python number formatting string to be used in labeling the flow as a quantity (i.e., a number times a unit, where the unit is given) *gap* space between paths that break in/break away to/from the top or bottom *radius* inner radius of the vertical paths *shoulder* size of the shoulders of output arrowS *offset* text offset (from the dip or tip of the arrow) *head_angle* angle of the arrow heads (and negative of the angle of the tails) [deg] *margin* minimum space between Sankey outlines and the edge of the plot area *tolerance* acceptable maximum of the magnitude of the sum of flows The magnitude of the sum of connected flows cannot be greater than *tolerance*. =============== =================================================== The optional arguments listed above are applied to all subdiagrams so that there is consistent alignment and formatting. If :class:`Sankey` is instantiated with any keyword arguments other than those explicitly listed above (``**kwargs``), they will be passed to :meth:`add`, which will create the first subdiagram. In order to draw a complex Sankey diagram, create an instance of :class:`Sankey` by calling it without any kwargs:: sankey = Sankey() Then add simple Sankey sub-diagrams:: sankey.add() # 1 sankey.add() # 2 #... sankey.add() # n Finally, create the full diagram:: sankey.finish() Or, instead, simply daisy-chain those calls:: Sankey().add().add... .add().finish() See Also -------- Sankey.add Sankey.finish Examples -------- .. plot:: gallery/specialty_plots/sankey_basics.py r zS'gap' is negative, which is not allowed because it would cause the paths to overlapz`'radius' is greater than 'gap', which is not allowed because it would cause the paths to overlapzp'head_angle' is negative, which is not allowed because it would cause inputs to look like outputs and vice versaz3'tolerance' is negative, but it must be a magnitudeNr )ZxticksZyticksg �f@� @)� ValueErrorZmatplotlib.pyplotZpyplotZfigureZadd_subplot�diagrams�ax�unit�format�scale�gap�radius�shoulder�offset�margin�npZtanZpi�pitch� tolerance�array�inf�extent�len�add)�selfr r r r r r r r Z head_angler r# �kwargsZpltZfig� r+ �3/usr/lib/python3/dist-packages/matplotlib/sankey.py�__init__* sF Q���� zSankey.__init__r Tr �r r c C s" t jt jt jt jt jt jt jg}t�ddgddgddgddgddgddgddgg�}|dksd|dkr�|rn|}q�|d d �d d d �f }nf|dks�|dkr�|r�t�|d d �df |d d �df f�}n(t�|d d �df |d d �df f�}|dkr�| }tt||| t�||j d df� ��S ) a= Return the codes and vertices for a rotated, scaled, and translated 90 degree arc. Optional keyword arguments: =============== ========================================== Keyword Description =============== ========================================== *quadrant* uses 0-based indexing (0, 1, 2, or 3) *cw* if True, clockwise *center* (x, y) tuple of the arc's center =============== ========================================== r g gw,���?g����S��?g�����?g>�ef���?r � N���r r ) r �LINETO�CURVE4r! r$ Zcolumn_stack�list�zipZtile�shape)r) �quadrant�cwr �centerZ ARC_CODESZARC_VERTICES�verticesr+ r+ r, �_arc� sB � � ���zSankey._arcc C s |dkrddgddgfS |d d \}}|d | j }|tkr�||8 }|| ||d g}|�tj||gftj|ftj||| gftj|| j || gfg� |d | j |d g} �nJ|| j8 }|tkr�d} nd} ||d || || g}|tk�r d}nd}| j �r@|�| j ||tk| j || j || | j fd�� n|�tj||gf� |�tj||| | gftj|ftj|| || | gfg� |�| j ||tk|| j || j || | j fd�� |�tj|| || | gf� |d |d | | j g} || fS dS )zP Add an input to a path and return its tip and label locations. Nr r0 r r/ r �r6 r7 r r8 )r"