o
    ˷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 q6ejddD ]\ZZZed	 d
k rUeee qDe	jddZdd eD ZzddlmZ ddlm  mZ  ej!g de" ddZ#e#$g de%  dD ]Z&e j'dde&dZ(e#j)e *e(+ e, ddd qe#j-e.dd ej/0 D j1dd eD ee, dd e D ]$Z2e.dd e2D Z3e#j4e3dddf e3dddf e, d dd! qW n e5y   ej6eej/d"d eD edd# Y nw e	7  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 ]k}| }|dr"qt	
d}||rF| }|D ]}|j||| t|d |d }q2q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Gcitieslinenumfinddistdcityicoordpopcoordpopyx r+   z/var/www/ideatree/venv/lib/python3.10/site-packages/../../../share/doc/networkx-2.8.6/examples/drawing/plot_knuth_miles.pymiles_graph"   s2   




 r-   z+Loaded miles_dat.txt containing 128 cities.T)datar   i,  )      )figsizec                 C   s   g | ]	}t t|qS r+   )r   Hdegree.0vr+   r+   r,   
<listcomp>Z   s    r7   )r   r   r   r   F)
projectionframeon)ig     P   2   )"admin_1_states_provinces_lakes_shpadmin_0_countries110mcultural)
resolutioncategorynamenonek)	facecolor	edgecolorc                 C   s   g | ]}|qS r+   r+   r4   r+   r+   r,   r7   q   s    c                 C      g | ]}t j| qS r+   r   r   r4   r+   r+   r,   r7   r       r
   )sc	transformzorderc                 C   rG   r+   )r   r   r4   r+   r+   r,   r7   y   rI   r   g      ?)rL   	linewidthcolorc                 C   rG   r+   rH   r4   r+   r+   r,   r7      rI   )	node_size
node_colorwith_labels)8__doc__r   r   warningssimplefilternumpynpmatplotlib.pyplotpyplotpltnetworkxr   r-   r   printr   r2   r6   r   edgesur#   r   figurefigrQ   cartopy.crscrsccrscartopy.io.shapereaderioshapereader	shpreaderadd_axesLambertConformalax
set_extentGeodetic	shapenamenatural_earthshpadd_geometriesReader
geometriesPlateCarreescatterarrayr   valuesTedgeedge_coordsplotImportErrordrawshowr+   r+   r+   r,   <module>   s~    
'

