a
    1$e>                    @   sH  d dl Z d dlmZ d dlZd dlZd dlZd dlm	Z	 d dl
mZ d dlmZmZmZmZmZmZmZmZmZ d dlmZmZmZ d dlmZ d dlmZ d dlm Z  d dl!Z!e!"d	Z#e#$d
 d dl%m&Z' zd dl(m)Z) dZ*W n e+y   dZ*Y n0 e!j,dddd Z-ze#j.d / Z0e0d d  Z1W n" e2yP   e#j.d d  Z1Y n0 e'j.3dd i G dd dZ4G dd dZ5G dd dZ6G dd dZ7G dd dZ8G dd  d Z9G d!d" d"Z:G d#d$ d$Z;G d%d& d&Z<G d'd( d(Z=G d)d* d*Z>G d+d, d,Z?d-d. Z@d/d0 ZAd;d1d2ZBd3d4 ZCd5d6 ZDd7d8 ZEd9d: ZFdS )<    N)Version)wkt)rotate)	MultiPolygonPolygon
LineString
LinearRingPoint
MultiPointMultiLineStringGeometryCollectionbox)GeoDataFrame	GeoSeries	read_file)get_path)GeoplotAccessor
matplotlibZAgg)check_figures_equalTF)Zautousec                 c   s   d V  t d d S )Nall)pltclose)request r   Y/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopandas/tests/test_plotting.pyclose_figures*   s    r   zaxes.prop_cyclecolorzaxes.color_cyclezfigure.max_open_warningc                	   @   s4  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zejjeejedkoeejedk dddd Zdd Zdd  Zd!d" Zejd#ed$d$d%d%ed&d&d'd'ged(d)ged*d+gged%d%ed&d&ggd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Z d6d7 Z!d8S )9TestPointPlottingc                 C   s   d| _ tdd t| j D | _t| j }t| j|d| _|d d | jd< t| j}t	|d}t||gdd	gd| _
d S )
N
   c                 s   s   | ]}t ||V  qd S Nr	   .0ir   r   r   	<genexpr><       z1TestPointPlotting.setup_method.<locals>.<genexpr>geometryvalues   expZ   r      )Nr   rangepointsnparanger   dfr
   r   df2)selfr(   Zmultipoint1Zmultipoint2r   r   r   setup_method:   s    

zTestPointPlotting.setup_methodc                 C   sH   | j jdd}tj|j d | jjdd}tj|j d d S )Nr,   r,   )Zfigsize)r/   plotr0   testingassert_array_equalZfigureZget_size_inchesr2   r4   axr   r   r   test_figsizeI   s    zTestPointPlotting.test_figsizec                 C   s   | j  }t| j|jd  tg| j  | j }t| j|jd  tg| j  | jjdd}t	 }|t
| j| jd  }t| j|jd  | d S )Nr   r(   columnr,   )r/   r7   _check_colorsr-   collectionsget_facecolorsMPL_DFT_COLORr2   r   get_cmapr0   r1   r4   r;   cmapexpected_colorsr   r   r   test_default_colorsP   s    

z%TestPointPlotting.test_default_colorsc                 C   sf   t g d}| j|}|| jd< | jd}|jd  }|jd  }tj|d |d  d S )N)
abcrH   rI   rJ   rH   rI   rJ   rH   
colors_ordr   r,   	pdZSeriesr2   r7   r@   rA   r0   r8   r9   r4   rK   ax1ax2point_colors1point_colors2r   r   r   test_series_color_no_indexe   s    
z,TestPointPlotting.test_series_color_no_indexc                 C   sn   t jg dg dd}| j|}|| jd< | jd}|jd  }|jd  }tj|d |d  d S )N)
rH   rH   rH   rH   rI   rI   rI   rJ   rJ   rJ   )
r   r)      	   r,                  indexrK   r   r,   rL   rN   r   r   r   test_series_color_indexu   s    
z)TestPointPlotting.test_series_color_indexc                 C   s   | j jdd}td}|t| j| jd  }t| j|jd 	 | | j
jdd}t| j|jd 	 | | j
jddd}td}t| j|jd 	 | | j jtjddd	d}tjddd	}|ttdd
 }t| j|jd 	 | d S )NRdYlGnrE   r,   r   r(   )r>   rE   ZSet1rY   lutrX   )r/   r7   r   rC   r0   r1   r-   r?   r@   rA   r2   listr.   r4   r;   rE   
exp_colorsr   r   r   test_colormap   s    

zTestPointPlotting.test_colormapc                 C   sV  | j jdd}t| j|jd  dg| j  | jjdd}t| j|jd  dg| j  | jjdd}t| j|jd  dg| j  | jjdd}t| j|jd  dg| j  tt	t
f | jjdd W d    n1 s0    Y  tjdd@}| jjd	dd
}t| j|jd  dg| j  W d    n1 sH0    Y  d S )Ngreenr   r         ?ri   ri   ri   ri   ri   ri   	not colorTrecordr(   r>   r   )r/   r7   r?   r-   r@   rA   r2   pytestraises
ValueError	TypeErrorwarningscatch_warningsr4   r;   _r   r   r   test_single_color   s&      ,z#TestPointPlotting.test_single_colorc                 C   s   | j jdd}|jd  dgks&J | jjdd}|jd  dgksLJ | jjddd}|jd  dgkstJ | jjdd}|jd  | jd k sJ | jjddd}|jd  | jd k sJ d S )Nr   
markersizer   r(   )r>   ry   )r/   r7   r@   	get_sizesr2   r   r:   r   r   r   test_markersize   s     z!TestPointPlotting.test_markersizec                 C   s8   | j jdd}td}tj||jd  d j d S )N+)markerr   )	r3   r7   _style_to_verticesr0   r8   r9   r@   	get_pathsvertices)r4   r;   expectedr   r   r   test_markerstyle   s
    z"TestPointPlotting.test_markerstylec                 C   s0   | j jdd}|jd  g dk s,J d S )Nk)Z
edgecolorsr   )r   r   r   r,   )r/   r7   r@   get_edgecolorr   r:   r   r   r   test_style_kwargs   s    z#TestPointPlotting.test_style_kwargsc                 C   s   | j jdd}tjdg|jd   z | j jtddd| jd}W n t	yZ   Y n(0 tjtddd| j|jd   d S Nffffff?alphar                 ?
r2   r7   r0   r8   r9   r@   	get_alphalinspacer-   rr   r:   r   r   r   test_style_kwargs_alpha   s     z)TestPointPlotting.test_style_kwargs_alphaz	3.8.0.devz3.8.0zfailing with matplotlib devreasonc                 C   s  t jdd8}| jjdddd}t| jdks6J W d    n1 sJ0    Y  | jjdd}t| jdksxJ | jjdddd	}|jd
  }t	| jd  }t
j|d
 |d
  t
j|d |d  | jjdddd}|jd
  }| jjd  }t
j|d
 |d
  t
j|d |d  tjj| jdd  j | jdd  j d}| jdd  jddd|d}|jd
  }t	| jd  }t
j|d
 |d
  t
j|d |d  |jdksJ d S )NTrl   r(   rf   )r>   r   legendr,   r   r^   r>   rE   r   r   )r>   categoricalr   vminvmaxr*   )r>   rE   r   norm)   rV   )rs   rt   r2   r7   len
get_figureaxesr@   rA   _get_colorbar_axr0   r8   r9   
get_legendr   colorsZLogNormr*   minmaxshape)r4   rv   r;   point_colorsZcbar_colorsr   r   r   r   test_legend   s0    4$zTestPointPlotting.test_legendc                 C   s   t jj}t jjddd}| jjd||d}|jd  }|t	
dd }t	j|| t \}}| jdd  jd|||d |jd  }t	j|d |d  d S 	Nr      r   r(   r>   rE   r   r   r,   r>   r;   r   rE   r   cm	viridis_rr   	Normalizer2   r7   r@   rA   r0   r1   r8   r9   r   subplotsr4   rE   r   r;   Zactual_colors_origrd   figZactual_colors_subr   r   r   test_subplots_norm  s    z$TestPointPlotting.test_subplots_normc                 C   s   t t g}tt | }W d    n1 s40    Y  t|jdksPJ t g }tt | }W d    n1 s0    Y  t|jdksJ tg dgd}tt | }W d    n1 s0    Y  t|jdksJ d S )Nr   r'   )columns)	r   r   ro   warnsUserWarningr7   r   r@   r   )r4   sr;   r2   r   r   r   test_empty_plot$  s    &&&z!TestPointPlotting.test_empty_plotc                 C   s   t jrJttdg}ttg dtdg}| }t|jdksJJ t jsttg dt g}| }t|jdksJ tg d}t	dd}t	dd}t	 }t
|||gd}|||d< d g|jd	< | }t|jdksJ d S )
NzPOLYGON EMPTY)r   r   r,   r   r6   r,   )r   r   )r   rX   rX   rX   )rX   r   r   r   r   )r'   r'   r)   )compatZ
USE_PYGEOSr   r   loadsr   r7   r   r@   r	   r   intersectionloc)r4   r   r;   polypointZpoint_Zempty_pointgdfr   r   r   test_empty_geometry2  s(    

z%TestPointPlotting.test_empty_geometrygeomsr   r,   rW   rZ   r6   )r,   rX   )rW   r,   )rW   rX   c                 C   s   t |ddgd}|tdddd}|jddgd	}tg d
}|jd dkrptj|	 d 
 d | ntj|	 d  d | d S )NrrI   r[   rY   r   r   redbluerg   )r   r   r   r   r   )r   r   r   r7   r0   array	geom_typer8   r9   get_childrenr   get_facecolor)r4   r   r   s2r;   r   r   r   r   test_empty_geometry_colorsK  s     z,TestPointPlotting.test_empty_geometry_colorsc                 C   s   | j  }td|jd  tgd  | j jdd}tjdd}|dg| j |dg| j  }td|jd  | | j jd	d
gd}td|jd  d	gd d
gd   d S )NrV   r   r(   r=   rX   r`   r,   r   r   rI   rg   r   )	r3   r7   r?   r@   rA   rB   r   rC   r-   rD   r   r   r   test_multipointsi  s    
 z"TestPointPlotting.test_multipointsc                 C   s~   | j jdd}tjdg|jd   z| j jddgd}W n tyP   Y n*0 tjdgd dgd  |jd   d S )Nr   r   r   皙?r   r3   r7   r0   r8   r9   r@   r   rr   r:   r   r   r   test_multipoints_alphaw  s    z(TestPointPlotting.test_multipoints_alphac                 C   s  ddgd | j d< ddgd | j d< dgd | j d	< tddgd | j d
< tjdgd ddgd| j d< tjddgd ddgd| j d< ddgd | j d< tddgd | j d< tjddgd dd| j d< | j jddd}| j jd
dd}| j jd	ddgdd}| j jddd}| j jddd}| j jdddgdd}| j jddd}| j jddd}| j jddd}	|jd  }
||||||||	fD ]*}|jd  }tj	|
d |d  qdd |
  D }||||||||	fD ]*}dd |
  D }tj	|| qtt  | j jddd W d    n1 sB0    Y  tjtdd" | j jddgd W d    n1 s0    Y  tjtdd" | j jd
dgd W d    n1 s0    Y  d S ) NZcat1cat2rY   Zcats_objectr,   rX   numsr   Zsinglecat_objectZcats)
categoriesZ	singlecatZcats_orderedFTboolZbool_extensionstring)ZdtypeZcats_stringr   )r   r   r   c                 S   s   g | ]}|  qS r   Zget_markerfacecolorr"   xr   r   r   
<listcomp>  r%   z5TestPointPlotting.test_categories.<locals>.<listcomp>c                 S   s   g | ]}|  qS r   r   r   r   r   r   r     r%   Znon_list)r>   r   z0Column contains values not listed in categories.matchz+Cannot specify 'categories' when column has)r2   rM   ZCategoricalr   r7   r@   rA   r0   r8   r9   r   	get_linesro   rp   rr   rq   )r4   rO   rP   ax3ax4Zax5Zax6Zax7Zax8Zax9rQ   r;   rR   Zlegend1Zlegend2r   r   r   test_categories  sP    02z!TestPointPlotting.test_categoriesc                 C   sn  t j| jjd< | jd}t }|t | jd | jd  }t	| jd |j
d  | | jjdddid}t }|t | jd | jd  }t	d|j
d  dg t	| jd |j
d  | | jjdddid	d	d
}t	d|j
d  dg |j
d  }|j
d  }| jj
d  }| jj
d  }t j|d |d  t j|d |d  d S )N)r   r(   r(   r,   rX   r   r   r   )missing_kwdsT)r   r   r   )r0   nanr2   r   r7   r   rC   r1   r-   r?   r@   rA   r   r   r8   r9   )r4   r;   rE   rF   r   Z	nan_colorZ
leg_colorsZleg_colors1r   r   r   test_missing  s(    zTestPointPlotting.test_missingc                 C   s4   | j  }|d d|d< |jdddidd d S )Nr(   strcategory	facecolornoneT)r   r   )r2   copyZastyper7   )r4   r2   r   r   r    test_no_missing_and_missing_kwds  s    
z2TestPointPlotting.test_no_missing_and_missing_kwdsN)"__name__
__module____qualname__r5   r<   rG   rS   r]   re   rw   r{   r   r   r   ro   markZskipifr   r   __version__r   r   r   r   parametrizer   r   r	   r   r   r   r   r   r   r   r   r   r   r   9   sN   
-


0r   c                   @   s   e Zd Zdd Zdd ZdS )TestPointZPlottingc                 C   sB   d| _ tdd t| j D | _t| j }t| j|d| _d S )Nr   c                 s   s   | ]}t |||V  qd S r   r    r!   r   r   r   r$     r%   z2TestPointZPlotting.setup_method.<locals>.<genexpr>r&   )r-   r   r.   r/   r0   r1   r   r2   )r4   r(   r   r   r   r5     s    zTestPointZPlotting.setup_methodc                 C   s   | j   d S r   r2   r7   r4   r   r   r   	test_plot  s    zTestPointZPlotting.test_plotNr   r   r   r5   r   r   r   r   r   r     s   r   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )TestLineStringPlottingc                 C   s   d| _ t| j }tdd t| j D tdd| _t| j|d| _t	| jj
dd j}t	| jj
d	d
 j}t||gddgd| _tdd t| j D tdd| _t| j|d| _d S )Nr   c                 S   s*   g | ]"}t d |fd|d fd|fgqS r   rV   ri   rU   r   r!   r   r   r   r     r%   z7TestLineStringPlotting.setup_method.<locals>.<listcomp>Z
ABCDEFGHIJr[   r&   ABCDr   r,   c                 S   s*   g | ]"}t d |fd|d fd|fgqS r   )r   r!   r   r   r   r     r%   )r-   r0   r1   r   r.   rb   linesr   r2   r   r   r(   r3   linearringsdf3)r4   r(   Z
multiline1Z
multiline2r   r   r   r5     s"    z#TestLineStringPlotting.setup_methodc                 C   s  | j jdd}t| j|jd  dg| j  | jjdd}t| j|jd  dg| j  | jjdd}t| j|jd  dg| j  | jjdd}t| j|jd  dg| j  | jjdd}t| j|jd  dg| j  | jjdd}t| j|jd  dg| j  t	
ttf | jjdd W d    n1 sH0    Y  tjdd@}| jjddd	}t| j|jd  dg| j  W d    n1 s0    Y  d S )
Nrf   rg   r   rj   rk   Trl   r(   rn   )r   r7   r?   r-   r@   
get_colorsr2   r   r   ro   rp   rr   rq   rs   rt   ru   r   r   r   rw     s*        .z(TestLineStringPlotting.test_single_colorc                 C   s  | j jddd| jjddd| jjddddfD ]$}dddgfg|jd	  ks0J q0| j jd
dd}d	g dfg|jd	  ksJ dd t| jD }dd |D }| j j|dd| j j|dd| jj|dd| jjd|ddfD ]}||jd	  ksJ qd S )N:r,   	linestyle	linewidthr(   )r>   r  r  r   r   ffffff?r   r   r)   r   r,      r  c                 S   s   g | ]}d |d  qS ))dasheddotteddashdotsolidrV   r   r"   r   r   r   r   r   !  r%   zFTestLineStringPlotting.test_style_kwargs_linestyle.<locals>.<listcomp>c                 S   s   g | ]}t |d qS r,   _style_to_linestring_onoffseqr"   str   r   r   r   "  r%   Z
linestylesr  )r   r7   r2   r@   get_linestyler.   r-   r4   r;   lsexp_lsr   r   r   test_style_kwargs_linestyle  s    " z2TestLineStringPlotting.test_style_kwargs_linestylec                 C   s   | j jdd| jjdd| jjdddfD ]}tjdg|jd   q*dd t| j	D }| j j|d| j j|d| jj|d| jjd|dfD ]}tj||jd   qd S )	NrX   r  r(   )r>   r  r   c                 S   s   g | ]}d |d  qS ))r   r,   rX         @r   rY   r   r  r   r   r   r   5  r%   zFTestLineStringPlotting.test_style_kwargs_linewidth.<locals>.<listcomp>Z
linewidths)
r   r7   r2   r0   r8   r9   r@   get_linewidthsr.   r-   )r4   r;   Zlwr   r   r   test_style_kwargs_linewidth+  s    z2TestLineStringPlotting.test_style_kwargs_linewidthc                 C   s   | j jdd}tjdg|jd   z | j jtddd| jd}W n t	yZ   Y n(0 tjtddd| j|jd   d S r   r   r:   r   r   r   r   >  s     z.TestLineStringPlotting.test_style_kwargs_alphac                 C   sT   ddl m} |dddg}| jjd|d}|jd  d jd dddksPJ d S )	Nr   )
withStrokerZ   rI   )r  
foregroundZorange)r   Zpath_effectsZ_gc)Zmatplotlib.patheffectsr  r2   r7   r@   Zget_path_effects__dict__)r4   r  Zeffectsr;   r   r   r   test_style_kwargs_path_effectsK  s    z5TestLineStringPlotting.test_style_kwargs_path_effectsc                 C   s   t jj}t jjddd}| jjd||d}|jd  }|t	
dd }t	j|| t \}}| jdd  jd|||d |jd  }t	j|d |d  d S r   )r   r   r   r   r   r2   r7   r@   get_edgecolorsr0   r1   r8   r9   r   r   r   r   r   r   r   U  s    z)TestLineStringPlotting.test_subplots_normc                 C   s   | j  }t|jd  dks$J td|jd  tgd  | j d}tj	dd}|d|d|d|dg}td|jd  | | j jddgd	}td|jd  g d
 d S Nr   rV   r(   rX   r`   r,   r   rI   rg   )r   r   rI   rI   )
r3   r7   r   r@   r   r?   r!  rB   r   rC   rD   r   r   r   test_multilinestringsb  s    
z,TestLineStringPlotting.test_multilinestringsN)r   r   r   r5   rw   r  r  r   r   r   r#  r   r   r   r   r     s   
r   c                   @   s|   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )TestPolygonPlottingc                 C   s   t g d}t g d}t||gtdd| _t| jddgd| _t||g}t|d}t||gddgd| _t g d	}t|t	j
gd}t| j|g| _d S )
Nr   r   rX   r   rX   r,   ABr[   r   r,   r&      )r&  )r)   r   )r)   r,   )r   r   rb   polysr   r2   r   r   r3   r0   r   rM   concatr   )r4   t1t2
multipoly1
multipoly2t3Zdf_nanr   r   r   r5   t  s    
z TestPolygonPlotting.setup_methodc                 C   sx  | j jdd}td|jd  dgd  t|jd  dksDJ | jjdd}td|jd  dgd  t|jd  dksJ | jjdd}td|jd  dgd  | jjdd}td|jd  dgd  t	t
tf | jjdd W d    n1 s0    Y  tjdd	<}| jjd
dd}td|jd  dgd  W d    n1 sj0    Y  d S )Nrf   rg   rX   r   rh   rj   rk   Trl   r(   rn   )r*  r7   r?   r@   rA   r   r!  r2   ro   rp   rr   rq   rs   rt   ru   r   r   r   rw     s    .z%TestPolygonPlotting.test_single_colorc                 C   s   | j jddddd}|jd  }tj|d |d  | j jddddd}|jd  }tj|d |d  | jjdd}|jd  }tt	|d |d sJ d S )Nr(   Fr   )r>   r   r   r   r,   Tr=   )
r2   r7   r@   rA   r0   r8   r9   r   any	not_equal)r4   r;   actual_colorsr   r   r   test_vmin_vmax  s    z"TestPolygonPlotting.test_vmin_vmaxc                 C   sr  | j jdd}td|jd  dgd  | j jddd}| j jdd}tjdg|jd   | j	jd	dd}tjdg|jd   | j jd
ddd}td|jd  d
gd dd td|jd  dgd dd | j	jddd}td|jd  dgd  td|jd  dgd  | j	jddd}td|jd  dgd  td|jd  dgd  d S )Nr   r   rX   r   r   )r   r   	edgecolor)r,   r   r   r,   r(   gr   皙?)r   r7  r   r   rh   )r9  ri   333333?r   r7  rj   r9  ri   r:  ri   )
r*  r7   r?   r@   rA   r0   r8   r9   r!  r2   r:   r   r   r   test_style_kwargs_color  s,      z+TestPolygonPlotting.test_style_kwargs_colorc                 C   s   | j jddd}dddgfg|jd  ks0J | j jddd}dg d	fg|jd  ks`J d
dg}dd |D }| j j|dd| j j|ddfD ]}||jd  ksJ qd S )Nr   r,   r  r   r   r  r   r  r  r  r	  c                 S   s   g | ]}t |d qS r  r  r  r   r   r   r     r%   zCTestPolygonPlotting.test_style_kwargs_linestyle.<locals>.<listcomp>r  )r2   r7   r@   r  r  r   r   r   r    s      z/TestPolygonPlotting.test_style_kwargs_linestylec                 C   s   | j jdd}tjdg|jd   | j jddgd| j jddgdfD ] }tjddg|jd   qL| j jdd}tjdg|jd   z| j jddgd}W n ty   Y n0 tjddg|jd   d S )	NrX   r  r   rV   r  r   r   r   )	r2   r7   r0   r8   r9   r@   r  r   rr   r:   r   r   r   r    s    (z/TestPolygonPlotting.test_style_kwargs_linewidthc                    s   t | jd  }d | jjdd|d fdd|D ddd}t|t|  ks\J |  d	   szJ | 	 du sJ d S )
Nr(   Z
LABEL_FOR_Tc                    s   g | ]} t | qS r   )r   r"   rJ   prefixr   r   r      r%   z:TestPolygonPlotting.test_legend_kwargs.<locals>.<listcomp>F)labelsZframeon)r>   r   r   r   legend_kwdsr   )
rb   r2   uniquer7   r   r   	get_textsget_text
startswithZget_frame_on)r4   r   r;   r   r?  r   test_legend_kwargs  s    
z&TestPolygonPlotting.test_legend_kwargsc                 C   sr   d}| j jdddd|id}t| }| |ks8J | j jddd|ddd}t| }| |ksnJ d S )	Nzcolorbar testr(   FTlabelr>   r   r   rB  
horizontal)rH  Zorientation)r2   r7   r   r   Z
get_ylabelZ
get_xlabel)r4   Z	label_txtr;   caxr   r   r   test_colorbar_kwargs  s"    z(TestPolygonPlotting.test_colorbar_kwargsc                 C   s2   | j jdddddid | j jddddid d S )Nr(   Tfmt{:.0f}rI  )r>   r   rB  r   r   r   r   r   test_fmt_ignore   s    z#TestPolygonPlotting.test_fmt_ignorec                 C   s   | j  }t|jd  dks$J td|jd  tgd  | j d}tj	dd}|d|d|d|dg}td|jd  | | j jddgd	}td|jd  g d
 d S r"  )
r3   r7   r   r@   r   r?   rA   rB   r   rC   rD   r   r   r   test_multipolygons_color-  s    
z,TestPolygonPlotting.test_multipolygons_colorc                 C   s   | j jddd}dddgfg|jd  ks0J | j jddd}dg d	fg|jd  ks`J d
dg}dd |D }| j j|dd| j j|ddfD ]}||jd  ksJ qd S )Nr   r,   r  r   r   r  r   r  r  r  r	  c                 S   s$   g | ]}t d D ]}t|dqqS r'  )r.   r  )r"   r  r#   r   r   r   r   H  r%   zDTestPolygonPlotting.test_multipolygons_linestyle.<locals>.<listcomp>r  )r3   r7   r@   r  r  r   r   r   test_multipolygons_linestyle=  s      z0TestPolygonPlotting.test_multipolygons_linestylec                 C   sr   | j jdd}tjdg|jd   | j jddgd| j jddgdfD ] }tjg d|jd   qLd S )NrX   r  r   rV   r  )rX   rX   rV   rV   )r3   r7   r0   r8   r9   r@   r  r:   r   r   r   test_multipolygons_linewidthO  s    (z0TestPolygonPlotting.test_multipolygons_linewidthc                 C   sr   | j jdd}tjdg|jd   z| j jddgd}W n tyP   Y n0 tjg d|jd   d S )Nr   r   r   r   )r   r   r   r   r   r:   r   r   r   test_multipolygons_alphaZ  s    z,TestPolygonPlotting.test_multipolygons_alphac                 C   s   t jj}t jjddd}| jjd||d}|jd  }|t	
dd }t	j|| t \}}| jdd  jd|||d |jd  }t	j|d |d  d S )	Nr   r   r   r(   r   rX   r,   r   r   r   r   r   r   r   g  s    z&TestPolygonPlotting.test_subplots_normN)r   r   r   r5   rw   r4  r=  r  r  rG  rL  rO  rP  rQ  rR  rS  r   r   r   r   r   r$  s  s   %r$  c                   @   s   e Zd Zdd Zdd ZdS )TestPolygonZPlottingc                 C   sv   t g d}t g d}t||gtdd| _t| jddgd| _t||g}t|d}t||gddgd| _d S )	N))r   r   r   r,   r   r   )r,   r,   r,   )rU  )rX   r   r   )rX   r,   r,   r(  r[   r   r,   r&   r)  )	r   r   rb   r*  r   r2   r   r   r3   )r4   r,  r-  r.  r/  r   r   r   r5   v  s    
z!TestPolygonZPlotting.setup_methodc                 C   s   | j   d S r   r   r   r   r   r   r     s    zTestPolygonZPlotting.test_plotNr   r   r   r   r   rT  u  s   rT  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestColorParamArrayc                 C   sn   g }g }dD ]:\}}t ||||}|||dj|jg7 }|g d7 }qt||d| _| j| jj| _d S )N))r   rX   )rV   rT   g?)r   rf   r   )r'   
color_rgba)	r   bufferZexteriorZcentroidr   r   Zdissolver   mgdf)r4   Zgeomr   rH   rI   r   r   r   r5     s    z TestColorParamArray.setup_methodc                 C   st   | j j| j d d}tdtdd |jD dgd dgd   tdtd	d |jD d
gd dgd   d S )NrW  rg   rV   c                 S   s   g | ]}|  qS r   r   r>  r   r   r   r     r%   z9TestColorParamArray.test_color_single.<locals>.<listcomp>rf   rX   r   c                 S   s   g | ]}|  qS r   r   r>  r   r   r   r     r%   r   )r   r7   r?   r0   concatenater@   r:   r   r   r   test_color_single  s    z%TestColorParamArray.test_color_singlec                 C   st   | j j| j d d}tdtdd |jD dgd dgd   tdtd	d |jD d
gd dgd   d S )NrW  rg   rV   c                 S   s   g | ]}|  qS r   rZ  r>  r   r   r   r     r%   z8TestColorParamArray.test_color_multi.<locals>.<listcomp>rf   rX   r   c                 S   s   g | ]}|  qS r   r[  r>  r   r   r   r     r%   r   )rY  r7   r?   r0   r\  r@   r:   r   r   r   test_color_multi  s    z$TestColorParamArray.test_color_multiN)r   r   r   r5   r]  r^  r   r   r   r   rV    s   rV  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestGeometryCollectionPlottingc                 C   s^   t tg dtddgg}t tddtg dg}t||g| _t| jddgd	| _d S )
Nr%  )ri   ri   r6   )r,   ri   g      ?r,         ?      ?)r   )r)   rX   )rX   r)   r,   rX   r&   )r   r   r   r	   r   seriesr   r2   )r4   Zcoll1Zcoll2r   r   r   r5     s    

z+TestGeometryCollectionPlotting.setup_methodc                 C   s^   | j  }td|jd  tgd  td|jd  tgd  td|jd  tg d S )NrX   r   r,   )re  r7   r?   r@   rA   rB   r!  r:   r   r   r   test_colors  s    
z*TestGeometryCollectionPlotting.test_colorsc                 C   sv   | j d}t }|ddg}td|jd  | td|jd  |d gd  td|jd  |d g d S )Nr(   r   r   rX   r   r,   )r2   r7   r   rC   r?   r@   rA   r!  rc   r   r   r   test_values  s    z*TestGeometryCollectionPlotting.test_valuesN)r   r   r   r5   rf  rg  r   r   r   r   r_    s   r_  c                   @   sh   e Zd Zdd Zdd Zdd Zdd Zejj	d	d
dd Z
dd Zejj	d	d
dd Zdd ZdS )TestNonuniformGeometryPlottingc                 C   sV   t d tg d}tg d}tdd}t|||g| _t| jg dd| _d S )Nr   r%  )r`  r6   ra  rb  rc  rd  r,   rX   r)   r&   )	ro   importorskipr   r   r	   r   re  r   r2   )r4   r   liner   r   r   r   r5     s    

z+TestNonuniformGeometryPlotting.setup_methodc                 C   s   | j  }td|jd  tg td|jd  tg td|jd  tg | j jdd}td}|t	
dd }td|jd  |d g td|jd  |d g td|jd  |d g d S )Nr,   r   rX   r^   r_   r)   )re  r7   r?   r@   rA   rB   r!  r   rC   r0   r1   rc   r   r   r   rf    s    

z*TestNonuniformGeometryPlotting.test_colorsc                 C   sP   | j jdd}|jd  dgks&J | jjdd}|jd  dgksLJ d S )Nr   rx   rX   )re  r7   r@   rz   r2   r:   r   r   r   r     s    z0TestNonuniformGeometryPlotting.test_style_kwargsc                 C   sz   | j jddd| jjdddfD ]$}dddgfg|jd  ks J q | j jddd}dg d	fg|jd  ksvJ d S )
Nr   r,   r  r   r   r  r   r  r  re  r7   r2   r@   r  r:   r   r   r   r    s    "z:TestNonuniformGeometryPlotting.test_style_kwargs_linestylezDarray-like style_kwds not supported for mixed geometry types (#1379)r   c                 C   sd   g d}dd |D }| j j|dd| j j|dd| jj|ddfD ]}||jd  ksDJ qDd S )N)r  r	  r
  c                 S   s   g | ]}t |d qS r  r  )r"   styler   r   r   r     r%   zWTestNonuniformGeometryPlotting.test_style_kwargs_linestyle_listlike.<locals>.<listcomp>r,   r  r  r   rl  )r4   r  r  r;   r   r   r   $test_style_kwargs_linestyle_listlike   s    zCTestNonuniformGeometryPlotting.test_style_kwargs_linestyle_listlikec                 C   s,   | j jdd}tjdg|jd   d S )NrX   r  r   )r2   r7   r0   r8   r9   r@   r  r:   r   r   r   r    s    z:TestNonuniformGeometryPlotting.test_style_kwargs_linewidthc                 C   sZ   | j jg dd| j jg dd| jjg ddfD ] }tjg d|jd   q4d S )N)rX   rV   r  r  r   )re  r7   r2   r0   r8   r9   r@   r  r:   r   r   r   $test_style_kwargs_linewidth_listlike  s    zCTestNonuniformGeometryPlotting.test_style_kwargs_linewidth_listlikec                 C   s,   | j jdd}tjdg|jd   d S )Nr   r   r   )r2   r7   r0   r8   r9   r@   r   r:   r   r   r   r   !  s    z6TestNonuniformGeometryPlotting.test_style_kwargs_alphaN)r   r   r   r5   rf  r   r  ro   r   skiprn  r  ro  r   r   r   r   r   rh    s   	

rh  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestGeographicAspectc                 C   sl   t d}t|}|j|jdk | _| jd| _| jj}t	|d |d g}dt
|tj d  | _d S )Nnaturalearth_lowreszNorth AmericazESRI:102008r,   r)   r)  )r   r   r   Z	continentnorthZto_crs
north_projZtotal_boundsr0   meancospir*   )r4   pthr2   ZboundsZy_coordr   r   r   setup_class2  s    z TestGeographicAspect.setup_classc                 C   s   | j j }| | jksJ | jj }| dv s:J | j  }| | jksVJ | j }| dv spJ | j d}| | jksJ | jd}| dv sJ d S )Nequalr   pop_est)rs  r'   r7   
get_aspectr*   rt  )r4   r;   rP   r   r   r   r   r   	test_auto;  s    

zTestGeographicAspect.test_autoc                 C   s`  | j jjdd}| dv s J | j jj|d d | dv sBJ | j jjdd}| dksbJ | j jj|d d | dksJ | jjjdd}| dksJ | jjj|d d | dksJ | j jdd}| dv sJ | j j|d d | dv sJ | j jdd}| dks&J | j j|d d | dksHJ | jjdd}| dkshJ | jj|d d | dksJ | j jddd}| dv sJ | j jd|d d | dv sJ | j jddd}| dksJ | j jd|d d | dksJ | jjddd}| dks8J | jjd|d d | dks\J d S )Nr{  )aspectrz  )r;   r  ri   r|  )rs  r'   r7   r}  rt  )r4   r;   rP   r   r   r   r   test_manualI  sH    z TestGeographicAspect.test_manualN)r   r   r   ry  r~  r  r   r   r   r   rq  1  s   	rq  c                   @   s   e Zd Zedd Zdd Zdd Zdd Zd	d
 Zdd Z	dd Z
ejdddgdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"S )#TestMapclassifyPlottingc                 C   s  zdd l }W n ty(   td Y n0 || _t|jj| _| jd t	d}t
|| _tddt| jj| jd< tdd| jjd | jd	< tdd
| jjd | jd< td
d| jjd | jd< tj| jj| jjd dd df< t
t	d| _g d| jd< d S )Nr   mapclassifyUserDefinedrr  ir   	NEGATIVES333333?low_valsr   mid_valsr   	high_valsr   rX   nybb)gMbP?gMb`?g~jth?gMbp?g{Gzt?vals)r  ImportErrorro   rj  mcrb   classifiersZCLASSIFIERSremover   r   r2   r0   r   r   r\   r   r   r   r  )clsr  rx  r   r   r   ry  q  s     
 z#TestMapclassifyPlotting.setup_classc                 C   s   t jdd&}| jjdddddd}W d    n1 s80    Y  dd	 |  D }d
d	 t| jj| jd dd	ddd  D }||ksJ d S )NTrl   r|  	QUANTILESr)   OrRdr>   schemer   rE   r   c                 S   s   g | ]}|  qS r   rE  r"   tr   r   r   r     r%   z7TestMapclassifyPlotting.test_legend.<locals>.<listcomp>c                 S   s"   g | ]}| d d dd qS |r   r,   splitr"   r   r   r   r   r     s   )r   
rV   )
rs   rt   r2   r7   r   rD  r   r  Z	Quantilesr  )r4   rv   r;   rA  r   r   r   r   r     s    
$&z#TestMapclassifyPlotting.test_legendc              	   C   sN   | j jddddddg did}d	d
 |  D }g d}||ksJJ d S )Nr|  r  r)   r  TrA  )foobarZbazr>   r  r   rE   r   rB  c                 S   s   g | ]}|  qS r   r  r  r   r   r   r     r%   z;TestMapclassifyPlotting.test_bin_labels.<locals>.<listcomp>r2   r7   r   rD  r4   r;   rA  r   r   r   r   test_bin_labels  s    
z'TestMapclassifyPlotting.test_bin_labelsc              
   C   sN   t t0 | jjddddddddgid	 W d    n1 s@0    Y  d S )
Nr|  r  r)   r  TrA  r  r  r  ro   rp   rq   r2   r7   r   r   r   r   test_invalid_labels_length  s    
z2TestMapclassifyPlotting.test_invalid_labels_lengthc                 C   sD   | j jdddddd}dd |  D }g d	}||ks@J d S )
Nr  FISHER_JENKSr)   r  Tr  c                 S   s   g | ]}|  qS r   r  r  r   r   r   r     r%   z@TestMapclassifyPlotting.test_negative_legend.<locals>.<listcomp>)z-10.00,  -3.41z -3.41,   3.30z  3.30,  10.00r  r  r   r   r   test_negative_legend  s    
z,TestMapclassifyPlotting.test_negative_legendc                 C   sJ   | j jdddddddid}d	d
 |  D }g d}||ksFJ d S )Nr  r  r)   r  TrM  rN  r  c                 S   s   g | ]}|  qS r   r  r  r   r   r   r     r%   z4TestMapclassifyPlotting.test_fmt.<locals>.<listcomp>)z-10,  -3z -3,   3z  3,  10r  r  r   r   r   test_fmt  s    z TestMapclassifyPlotting.test_fmtc                 C   sJ   | j jdddddddid}dd	 |  D }g d
}||ksFJ d S )Nr  r  r)   r  Tintervalr  c                 S   s   g | ]}|  qS r   r  r  r   r   r   r     r%   z9TestMapclassifyPlotting.test_interval.<locals>.<listcomp>)z[-10.00,  -3.41]z( -3.41,   3.30]z(  3.30,  10.00]r  r  r   r   r   test_interval  s    z%TestMapclassifyPlotting.test_intervalr  r  ZFISHERJENKSc                 C   s0   | j jd|ddd}t|  dks,J d S )Nr  r)   T)r>   r  r   r   )r2   r7   r   r   rD  )r4   r  r;   r   r   r   test_scheme_name_compat  s    z/TestMapclassifyPlotting.test_scheme_name_compatc                 C   s"   | j D ]}| jjd|dd qd S )Nr|  T)r>   r  r   )r  r2   r7   r4   r  r   r   r   test_schemes  s    
z$TestMapclassifyPlotting.test_schemesc                 C   s|   | j jddddddgiddd	}d
d |  D }dd t| jj| j d ddgdddd  D }||ksxJ d S )Nr|  Zpercentilesr)   pct2   d   r  T)r>   r  r   classification_kwdsrE   r   c                 S   s   g | ]}|  qS r   r  r  r   r   r   r     r%   zDTestMapclassifyPlotting.test_classification_kwds.<locals>.<listcomp>c                 S   s"   g | ]}| d d dd qS r  r  r  r   r   r   r     s   )r  r  rV   )r2   r7   r   rD  r   r  ZPercentilesr  r  r   r   r   test_classification_kwds  s"    
z0TestMapclassifyPlotting.test_classification_kwdsc                 C   sH   t t* d}| jjd|dddd W d    n1 s:0    Y  d S )Nzinvalid_scheme_*#&)(*#Z
gdp_md_estr)   r  Tr  r  r  r   r   r   test_invalid_scheme  s
    
z+TestMapclassifyPlotting.test_invalid_schemec                 C   sn   t  }ddlm} ||}|jdddd}tt$ | jj	ddd	|d
}W d   n1 s`0    Y  dS )zPass a 'cax' argument to 'df.plot(.)', that is valid only if 'ax' is
        passed as well (if not, a new figure is created ad hoc, and 'cax' is
        ignored)
        r   make_axes_locatableright5%皙?)sizepadr|  r  T)r>   rE   r   rK  N)
r   r   mpl_toolkits.axes_grid1r  append_axesro   rp   rq   r2   r7   )r4   r;   r  dividerrK  r   r   r   test_cax_legend_passing  s    z/TestMapclassifyPlotting.test_cax_legend_passingc           
      C   s(  t jdd"}| jjdddd}W d   n1 s40    Y  t| d j}t| d j}t|| d	kszJ t	
 \}}d
dlm} ||}|jddddd}	t jdd&}| jjddd|	|d}W d   n1 s0    Y  t|d j}t|d j}t|| d	k s$J dS )zqPass a cax argument to 'df.plot(.)', the legend location must be
        aligned with those of main plot
        Trl   r|  r  r   N 
<colorbar>gư>r   r  r  r  r  Zfixed_colorbar)r  r  rH  )r>   rE   r   rK  r;   )rs   rt   r2   r7   _get_axr   get_positionheightabsr   r   r  r  r  )
r4   rv   r;   Zplot_heightZlegend_heightr   rP   r  r  rK  r   r   r   test_cax_legend_height  s     0
$z.TestMapclassifyPlotting.test_cax_legend_heightc                    s  t ddd }| jjddd|idd}t g d	g d
g dg t fdd|jd  D shJ g d}dd | 	 D }||ksJ g d}dd | 
 D |ksJ | jjddd|idd}t g dg dg dg dg dg t fdd|jd  D sJ g d}dd | 	 D }||ksJJ dd | 
 D |ksjJ | jjddd|idd}t g dg dg d g t fd!d|jd  D sJ d"d | 	 D }||ksJ d#d | 
 D |ksJ d S )$Nr,      r   r  r  binsT)r  r  r   g,z?g/lV^?g c?r   g ?g{is?g0"?r   gi7>[?g~8gDi?g].;1?r   c                 3   s"   | ]}| kj d d V  qdS r,   )ZaxisNr   r1  r"   zr   r   r   r$   #  s   z:TestMapclassifyPlotting.test_empty_bins.<locals>.<genexpr>r   )
z
0.00, 0.10
0.10, 0.20
0.20, 0.30
0.30, 0.40
0.40, 0.50
0.50, 0.60
0.60, 0.70
0.70, 0.80
0.80, 0.90
0.90, 1.00c                 S   s   g | ]}|  qS r   r  r  r   r   r   r   3  r%   z;TestMapclassifyPlotting.test_empty_bins.<locals>.<listcomp>)
r  r  r  gHMf?gI?gJ({?r   gB?gDi`?gǟlX?r   g(]?g\?g	/)?r   gK?gGS=?gTC?r   g*r9?gF^?gPT6,?r   gݯ|?g?g=ϟ6?r   g5(?gS<?g~[~l?r   c                 S   s   g | ]}|  qS r   r   r"   rk  r   r   r   r   C  s   r  r  r  r  r  c                 3   s"   | ]}| kj d d V  qdS r  r  r  r  r   r   r$   V  s   )
z
-inf, 0.10r  r  r  r  r  r  r  r  r  c                 S   s   g | ]}|  qS r   r  r  r   r   r   r   g  r%   c                 S   s   g | ]}|  qS r   r   r  r   r   r   r   i  s   r  r  r  r  c                 3   s"   | ]}| kj d d V  qdS r  r  r  r  r   r   r$   z  s   c                 S   s   g | ]}|  qS r   r  r  r   r   r   r     r%   c                 S   s   g | ]}|  qS r   r   r  r   r   r   r     s   )r0   r1   r2   r7   r   r   r@   rA   r   rD  r   )r4   r  r;   rA  r   Zlegend_colors_exprP   r   r   r  r   test_empty_bins  s    
	


z'TestMapclassifyPlotting.test_empty_binsc                 C   s   | j jdddd}dd |  D }g d}||ks<J | j jddddd	id
}dd |  D }g d}||ks~J d S )Nr  Z	quantilesT)r  r   c                 S   s   g | ]}|  qS r   r  r  r   r   r   r     r%   zGTestMapclassifyPlotting.test_equally_formatted_bins.<locals>.<listcomp>)
0.00, 0.00r  r  r  z
0.00, 0.01rM  z{:.3f})r  r   rB  c                 S   s   g | ]}|  qS r   r  r  r   r   r   r     r%   )z0.001, 0.002z0.002, 0.003z0.003, 0.003z0.003, 0.004z0.004, 0.005)r  r7   r   rD  )r4   r;   rA  r   rP   r   r   r   test_equally_formatted_bins  s    z3TestMapclassifyPlotting.test_equally_formatted_binsN)r   r   r   classmethodry  r   r  r  r  r  r  ro   r   r   r  r  r  r  r  r  r  r  r   r   r   r   r  p  s"   

rr  c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )TestPlotCollectionsc                 C   sf   d| _ t| j | _tdd t| j D | _tdd t| j D | _tdd t| j D | _d S )Nr)   c                 s   s   | ]}t ||V  qd S r   r    r!   r   r   r   r$     r%   z3TestPlotCollections.setup_method.<locals>.<genexpr>c                 S   s*   g | ]"}t d |fd|d fd|fgqS r   r   r!   r   r   r   r     r%   z4TestPlotCollections.setup_method.<locals>.<listcomp>c                 S   s*   g | ]"}t d |fd|d fd|fgqS r   )r   r!   r   r   r   r     r%   )	r-   r0   r1   r(   r   r.   r/   r   polygonsr   r   r   r   r5     s    z TestPlotCollections.setup_methodc                 C   s  ddl m}m} ddlm} t \}}||| j}t||sBJ |	  ||| j}t
| j| tg| j  |	  ||| jdd}t
| j| dg| j  t
| j| dg| j  |	  ||| jddd}t
| j| dg| j  t
| j| dg| j  |	  ||| jg dd}t
| j| g d t
| j| g d |	  ||| jg d	d}t
| j| g d	 t
| j| g d	 |	  tttf  ||| jd
d W d    n1 s0    Y  tt ||| j W d    n1 s0    Y  d S )Nr   )_plot_point_collectionplot_point_collection)PathCollectionr8  rg   r   r;  r   r8  rI   rj   )r  r   r  ri   r<  rk   )geopandas.plottingr  r  matplotlib.collectionsr  r   r   r/   
isinstanceclar?   r-   rA   rB   r!  ro   rp   rr   rq   r   FutureWarning)r4   r  r  r  r   r;   collr   r   r   test_points  sR    0zTestPlotCollections.test_pointsc                 C   sj   ddl m} t \}}||| j| j}|j  t }|t	
| j| jd  }t| j| | d S )Nr   )r  r,   )r  r  r   r   r/   r(   canvas	draw_idlerC   r0   r1   r-   r?   rA   )r4   r  r   r;   r  rE   rF   r   r   r   test_points_values  s    
z&TestPlotCollections.test_points_valuesc           	      C   s4  ddl m}m} ddlm} t \}}||| j}t||sBJ |	  ||| j}t
| j| tg| j  |	  ||| jdd}t
| j| dg| j  |	  ||| jddd}t
| j| dg| j  t
| j| dg| j  |	  ||| jg dd}t
| j| g d |	  ||| jg d	d}t
| j| g d	 |	  ||| jd
dd}tdd}| d }|d |d ksJ |d |d ksJ |	  tttf  ||| jdd W d    n1 s0    Y  tt ||| j W d    n1 s&0    Y  d S )Nr   )_plot_linestring_collectionplot_linestring_collection)LineCollectionr8  rg   r   r;  r  r  z--r,   r  r  rk   )r  r  r  r  r  r   r   r   r  r  r?   r-   	get_colorrB   r   rA   r!  r  r  ro   rp   rr   rq   r   r  )	r4   r  r  r  r   r;   r  r  Zres_lsr   r   r   test_linestrings  sP    
0z$TestPlotCollections.test_linestringsc                 C   s  ddl m} t \}}||| j| j}|j  t }|t	
| j| jd  }t| j| | |  ||| j| jdd}|j  td}|t	
| j| jd  }t| j| | |  ||| j| jddd}|j  t }|dg}t| j| |d  |  d S )	Nr   )r  r,   RdBur_   r)   rY   r   )r  r  r   r   r   r(   r  r  rC   r0   r1   r-   r?   r  r  )r4   r  r   r;   r  rE   rF   r   r   r   test_linestrings_values4  s(    




z+TestPlotCollections.test_linestrings_valuesc                 C   sz  ddl m}m} ddlm} t \}}||| j}t||sBJ |	  ||| j}t
| j| tg| j  t| dksJ |	  ||| jdd}t
| j| dg| j  t
| j| dg| j  |	  ||| jg dd}t
| j| g d t
| j| g d |	  ||| jg dd}t
| j| g d t
| j| g d |	  ||| jdd}t
| j| dg| j  t| dksJ |	  ||| jdd	d
}t
| j| dg| j  t
| j| d	g| j  |	  tttf  ||| jdd W d    n1 s40    Y  tt ||| j W d    n1 sl0    Y  d S )Nr   )_plot_polygon_collectionplot_polygon_collection)PatchCollectionr8  rg   )r8  rI   r   r  r5  r   r;  rk   )r  r  r  r  r  r   r   r  r  r  r?   r-   r   rB   r   r   ro   rp   rr   rq   r   r  )r4   r  r  r  r   r;   r  r   r   r   test_polygonsQ  s\    0z!TestPlotCollections.test_polygonsc                 C   s  ddl m} t \}}||| j| j}|j  t }|t	
| j| jd  }t| j| | |  ||| j| jdd}|j  td}|t	
| j| jd  }t| j| | |  ||| j| jddd}|j  t }|dg}t| j| |d  |  ||| j| jd	d
}|j  t }|t	
| j| jd  }t| j| | t| j| d	g| j  |  d S )Nr   )r  r,   r  r_   r)   rY   r   r8  r6  )r  r  r   r   r  r(   r  r  rC   r0   r1   r-   r?   r   r  r   )r4   r  r   r;   r  rE   rd   r   r   r   test_polygons_values  s6    





z(TestPlotCollections.test_polygons_valuesN)
r   r   r   r5   r  r  r  r  r   r  r   r   r   r   r    s   ;<?r  c                   @   sh   e Zd Zdd Zdd ZejZer\ej	
deeddgdd	d
 Zeddgddd Zdd ZdS )TestGeoplotAccessorc                 C   sR   t g dtddg}ddg}ddg}t|||ddd	| _t||d
| _d S )Nr   r,   r)   rX   r   r   )r'   r   yz	EPSG:4326)Zcrsr   r  )r   r	   r   r   rM   Z	DataFramer2   )r4   Z
geometriesr   r  r   r   r   r5     s    z TestGeoplotAccessor.setup_methodc           	      C   s   |  }| jjf ||d| |  }| jjf ||d| |  }t| jj|f d|i| |  }t| jj|f d|i| dS )zCompare Figures.)kindr;   r;   N)r   r2   r7   r   getattr)	r4   r  fig_testfig_refkwargsZax_pandas_1Zax_geopandas_1Zax_pandas_2Zax_geopandas_2r   r   r   compare_figures  s    z#TestGeoplotAccessor.compare_figuresr  ZpngZpdf)
extensionsc           	      C   s   ddl }ddg}dg}ddg}i }||v rx|jdstjtd	d
 | jj|d W d   n1 sh0    Y  dS n4||v rddi}n"||v rddd}|dkrd|d< | |||| t	
d dS )zTest Pandas kind.r   NZkdeZdensitypieZscatterZhexbinZscipyzNo module named 'scipy'r   r  r  r   r  r   Zgridsizer   )	importlibutil	find_specro   rp   ModuleNotFoundErrorr   r7   r
  r   r   )	r4   r  r  r  r  Z_scipy_dependent_kindsZ_y_kindsZ	_xy_kindsr	  r   r   r   test_pandas_kind  s(    ,

z$TestGeoplotAccessor.test_pandas_kindc                 C   s@   |  }| jj|d |  }t| jjd|d td dS )zTest Geo kind.)r;   Zgeor   N)r   r   r7   r  r   r   )r4   r  r  rO   rP   r   r   r   test_geo_kind  s
    z!TestGeoplotAccessor.test_geo_kindc                 C   sz   t jtdd | jjdd W d   n1 s20    Y  t jtdd | jj  W d   n1 sl0    Y  dS )zTest invalid kinds.zerror is not a valid plot kindr   errorr  Nz1'GeoplotAccessor' object has no attribute 'error')ro   rp   rq   r   r7   AttributeErrorr  r   r   r   r   test_invalid_kind  s    ,z%TestGeoplotAccessor.test_invalid_kindN)r   r   r   r5   r
  r   Z_pandas_kindsMPL_DECORATORSro   r   r   r   r  r  r  r   r   r   r   r    s   	
r  c                  C   sv  t g d} t g d}t| |gtdd}t|ddgd}|jdd	}|jd  }|j|d d	}|jd  }tj	|| |j|d j
d	}|jd  }tj	|| |jdd
d}|jd  }|j|d d
d}|jd  }tj	|| |j|d j
d
d}|jd  }tj	|| tjtdd& |jtg dd	}W d   n1 sh0    Y  dS )z
    Check that the dataframe plot method returns same values with an
    input string (column in df), pd.Series, or np.array
    r   r%  r(  r[   r   r,   r&   r(   r=   T)r>   r   zdifferent number of rowsr   ri  N)r   r   rb   r   r7   r@   rA   r0   r8   r9   r(   ro   rp   rq   r   )r,  r-  r*  r2   r;   r   Zcolors_seriesZcolors_arrayr   r   r   test_column_values  s,    r  c                  C   s   ddl m}  ddlm} tdddtddgd}| |}t||sRJ |	 }t
jrt|jt|j  krdksn J n&t|jt|j  krd	ksn J d S )
Nr   )_PolygonPatch)	PathPatchg      $@)r   )rY   r   g      @      )r  r  Zmatplotlib.patchesr  r	   rX  
differencer
   r  r   r   ZGEOS_GE_390r   r   codes)r  r  Zpolygonpatchpathr   r   r   test_polygon_patch&  s    "(r"  c           	   	   C   s   ddl m} |j}tt|}ttt|| }t	|t	|ksJJ dt
||D ]4\}}||j||dksTJ d||j||dqTdS )aw  
    Asserts that the members of `collection` match the `expected_colors`
    (in order)

    Parameters
    ----------
    N : int
        The number of geometries believed to be in collection.
        matplotlib.collection is implemented such that the number of geoms in
        `collection` doesn't have to match the number of colors assignments in
        the collection: the colors will cycle to meet the needs of the geoms.
        `N` helps us resolve this.
    collection : matplotlib.collections.Collection
        The colors of this collection's patches are read from
        `collection.get_facecolors()`
    expected_colors : sequence of RGBA tuples
    alpha : float (optional)
        If set, this alpha transparency will be applied to the
        `expected_colors`. (Any transparency on the `collection` is assumed
        to be set in its own facecolor RGBA tuples.)
    r   )r   z0Different lengths of actual and expected colors!r   z{} != {}N)r   r   ZcolorConvertermaptuplerb   	itertoolsislicecycler   zipZto_rgbaformat)	r-   r3  rF   r   r   convZall_actual_colorsactualr   r   r   r   r?   9  s    
r?   c                 C   s    t j| \}}t j|||S )zConverts a linestyle string representation, namely one of:
        ['dashed',  'dotted', 'dashdot', 'solid'],
    documented in `Collections.set_linestyle`,
    to the form `onoffseq`.
    )r   r   Z_get_dash_patternZ_scale_dashes)r  r  offsetdashesr   r   r   r  a  s    r  c                 C   s   t j|  }|jd S )z(Converts a markerstyle string to a path.rX   )r   markersZMarkerStyler   r   )Zmarkerstyler!  r   r   r   r~   k  s    r~   c                 C   s2   | j D ]}| |kr|  S qtd|dS )z
    Helper function to not rely on the order of `fig.axes`.
    Previously, we did `fig.axes[1]`, but in matplotlib 3.4 the order switched
    and the colorbar ax was first and subplot ax second.
    zno ax found with label {0}N)r   Z	get_labelrq   r)  )r   rH  r;   r   r   r   r  r  s    

r  c                 C   s
   t | dS )Nr  )r  )r   r   r   r   r   ~  s    r   )N)Gr%  Zpackaging.versionr   rs   numpyr0   ZpandasrM   Zshapelyr   Zshapely.affinityr   Zshapely.geometryr   r   r   r   r	   r
   r   r   r   Z	geopandasr   r   r   Zgeopandas.datasetsr   Zgeopandas._compat_compatr   r  r   ro   rj  r   ZuseZmatplotlib.pyplotZpyplotr   Zmatplotlib.testing.decoratorsr   r  r  Zfixturer   ZrcParamsby_keyr'  rB   KeyErrorupdater   r   r   r$  rT  rV  r_  rh  rq  r  r  r  r  r"  r?   r  r~   r  r   r   r   r   r   <module>   sr   ,




      )%\?  6  I$
(
