U
    ª9%e  ã                
   @   s(  d Z ddlZddlZddlZe d¡ ddlZddlmZ	 ddl
Zdd„ Zeƒ Zedƒ eeƒ e ¡ ZeD ]Ze e¡ qlejddD ]"\ZZZed	 d
k rˆe ee¡ qˆe	jddZdd„ eD ƒZzddlmZ ddlm  mZ  ej!ddddge "¡ ddZ#e# $ddddge %¡ ¡ dD ]6Z&e j'dde&dZ(e#j)e  *e(¡ +¡ e ,¡ ddd q e#j-e .e/ej0 1¡ ƒ¡j2dd„ eD ƒee ,¡ ddœŽ e ¡ D ]JZ3e .d d„ e3D ƒ¡Z4e#j5e4dd…df e4dd…df e ,¡ d!dd" q–W n6 e6k
r   ej7eej0d#d„ eD ƒedd$ Y nX e	 8¡  dS )%a+  
===========
Knuth Miles
===========

`miles_graph()` returns an undirected graph over 128 US cities. The
cities each have location and population data.  The edges are labeled with the
distance between the two cities.

This example is described in Section 1.1 of

    Donald E. Knuth, "The Stanford GraphBase: A Platform for Combinatorial
    Computing", ACM Press, New York, 1993.
    http://www-cs-faculty.stanford.edu/~knuth/sgb.html

The data file can be found at:

- https://github.com/networkx/networkx/blob/main/examples/drawing/knuth_miles.txt.gz
é    NÚignorec                  C   s  t  dd¡} t ¡ }i |_i |_g }|  ¡ D ]Ö}| ¡ }| d¡rDq,t	 
d¡}| |¡rŒ| ¡ }|D ]$}|j||| t|ƒd |d }qdq,d}| d¡\}}	| d|¡ |	 d	¡\}
}|
 d
¡\}}| |¡ t|ƒ d t|ƒd f|j|< t|ƒd |j|< q,|S )zUReturn the cites example graph in miles_dat.txt
    from the Stanford GraphBase.
    zknuth_miles.txt.gzÚrÚ*z^\d+)Úweighté   ú[r   ú]ú,éd   iè  )ÚgzipÚopenÚnxÚGraphÚpositionÚ
populationÚ	readlinesÚdecodeÚ
startswithÚreÚcompileÚmatchÚsplitÚadd_edgeÚintÚinsertÚadd_nodeÚfloat)ÚfhÚGZcitiesÚlineZnumfindÚdistÚdZcityÚiZcoordpopZcoordÚpopÚyÚx© r&   ú€/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/../../../share/doc/networkx-3.1/examples/drawing/plot_knuth_miles.pyÚmiles_graph"   s0    



 r(   z+Loaded miles_dat.txt containing 128 cities.T)Údatar   i,  )é   é   )Zfigsizec                 C   s   g | ]}t t |¡ƒ‘qS r&   )r   ÚHZdegree©Ú.0Úvr&   r&   r'   Ú
<listcomp>Z   s     r0   r   F)Z
projectionZframeoniƒÿÿÿg      PÀé   é2   )Z"admin_1_states_provinces_lakes_shpZadmin_0_countriesZ110mZcultural)Ú
resolutionÚcategoryÚnameÚnoneÚk)Z	facecolorZ	edgecolorc                 C   s   g | ]}t j| ‘qS r&   ©r   r   r-   r&   r&   r'   r0   r   s     r
   )ÚsÚcÚ	transformZzorderc                 C   s   g | ]}t j| ‘qS r&   )r   r   r-   r&   r&   r'   r0   y   s     g      è?)r;   Z	linewidthÚcolorc                 C   s   g | ]}t j| ‘qS r&   r8   r-   r&   r&   r'   r0   ‰   s     )Z	node_sizeÚ
node_colorZwith_labels)9Ú__doc__r   r   ÚwarningsÚsimplefilterÚnumpyÚnpZmatplotlib.pyplotZpyplotZpltZnetworkxr   r(   r   Úprintr   r,   r/   r   ÚedgesÚur!   r   ZfigureZfigr=   Zcartopy.crsZcrsZccrsZcartopy.io.shapereaderÚioZshapereaderZ	shpreaderZadd_axesZLambertConformalZaxZ
set_extentZGeodeticZ	shapenameZnatural_earthZshpZadd_geometriesÚReaderZ
geometriesZPlateCarreeZscatterÚarrayÚlistr   ÚvaluesÚTÚedgeZedge_coordsZplotÚImportErrorZdrawÚshowr&   r&   r&   r'   Ú<module>   sz   
'  ÿü
ûûû