
    EVf)                     R   d dl Z d dlZd dlmZ d dlmZmZ d dlZd dl	m
Z
mZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d Zd Zd Z d Z! edgd      d        Z"d Z#d Z$ejJ                  jM                  d      d        Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.y)    N)assert_array_almost_equal)ImageTiffTags)collectionspatheffectspyplot
transformsrcParams
rc_context)RendererAgg)Figure)imread)Path)image_comparison)IdentityTransformc                     t        ddg      } | j                  d       | j                  j                  d       t	        j
                         }| j                  || j                         d       |j                  d       | j                  || j                         d       |j                  d       t        t        t        |      d         d	d
       y )N   皙?)r   r   r         ?none)	facecolor	edgecolorr   r   r   )              ?r   r      )decimal)r   set_facecolorpatch	set_alphaioBytesIOsavefigget_facecolorseekr   tupler   )figbufs     b/var/www/html/software/conda/envs/catlas/lib/python3.12/site-packages/matplotlib/tests/test_agg.pytest_repeated_save_with_alphar*      s     !S
Ck"II **,CKK++-   " HHQKKK++-   " HHQKeF3K$564&')    c            
      &   t        j                         } t        j                         \  }}t	        j
                  t        ddgddgddgddgddgg      g      }|j                  |       |j                  dd       t        j                  |        y )Ni   
   gMbP?r   )
r!   r"   pltsubplotsr   PathCollectionr   
add_artistset_xlimr#   )bufffax
collections       r)   !test_large_single_path_collectionr9   3   s    ::<D
 LLNEAr++	Qx"a2r(S"IQx@	ABDJMM*KKKKr+   c                     t        j                  d      \  } }d}t        j                  |      }|j	                  |       |j                  ||dz  |dz         t        j                         }| j                  |d       y )Nr     g?g333333?pngformat)	r0   r1   nparangesemilogxfill_betweenr!   r"   r#   )r'   r7   stepsdatar(   s        r)   test_marker_with_nanrE   A   sg     ll1oGCE99UDKKOOD$s(DH-
**,CKKEK"r+   c                      t        j                         } t               }|j                         }t	        j
                  d      }|d d dxx   dz  cc<   |j                  |       |j                  | d       y )N順    r<   r=   )r!   r"   r   r1   r?   onesplotr#   )r5   r'   r7   pointss       r)   test_long_pathrM   M   sZ    ::<D
(C	BWWWF
3Q3K2KGGFOKKUK#r+   zagg_filter.pngT)remove_textc                     d d"fd	 G d d      }  G d d|        G fdd	|        G fd
d|       }t        j                         \  }}|j                  g dg dddddddd	      \  }|j                  g dg dddddddd	      \  } |d      }||fD ]  }|j                         }|j	                         }	|j                  ||	      \  }
|
j                  |       t        j                  |j                         |j                  ddd      }|
j                  |       |
j                  |j                         dz
         |
j                  |       |
j                  d        |j                  dd        |j!                  dd        |j"                  j%                  d!       |j&                  j%                  d!       y )#Nc                     t         j                  d| d   z  | |dd   z
  | d| d   z  | d| d   z
  f   }t        j                  |      }t        j                  ||j	                         z  |d      }||dz
  | dz    S )NrH   r   r   rI   same)mode)r?   r_hanningconvolvesum)x
window_lenswys        r)   smooth1dz!test_agg_filter.<locals>.smooth1dY   s    EEadFQz!B''AaeGaJ;r8I6J,JJLJJz"KK!%%'	162Azk!m,,r+   r   c                     t        t        |      d      dz  dz   }t        j                  d| |      } t        j                  d| |      } | S )Nr   rH   r   r   )maxintr?   apply_along_axis)AsigmarX   r\   s      r)   smooth2dz!test_agg_filter.<locals>.smooth2da   sN    UQ'!+a/
!Q
;!Q
;r+   c                       e Zd Zd Zd Zd Zy)#test_agg_filter.<locals>.BaseFilterc                      y)Nr    selfdpis     r)   get_padz+test_agg_filter.<locals>.BaseFilter.get_padi   s    r+   c                     t        d      )Nz"Should be overridden by subclasses)NotImplementedError)ri   
padded_srcrj   s      r)   process_imagez1test_agg_filter.<locals>.BaseFilter.process_imagel   s    %&JKKr+   c                     | j                  |      }t        j                  |||f||fdgd      }| j                  ||      }|| | fS )Nr   constant)rk   r?   padro   )ri   imrj   rr   rn   	tgt_images         r)   __call__z,test_agg_filter.<locals>.BaseFilter.__call__o   sW    ,,s#Cc3Z#sV$D *,J**:s;IsdSD((r+   N)__name__
__module____qualname__rk   ro   ru   rg   r+   r)   
BaseFilterre   g   s    		L	)r+   ry   c                        e Zd ZddZd Zd Zy)%test_agg_filter.<locals>.OffsetFilterc                     || _         y N)offsets)ri   r~   s     r)   __init__z.test_agg_filter.<locals>.OffsetFilter.__init__x   s	    "DLr+   c                 J    t        t        | j                        dz  |z        S )NH   )r_   r^   r~   rh   s     r)   rk   z-test_agg_filter.<locals>.OffsetFilter.get_pad{   s     s4<<(2-344r+   c                     | j                   \  }}t        j                  |t        |dz  |z        d      }t        j                  |t        |dz  |z         d      }|S )Nr   r   )axisr   )r~   r?   rollr_   )ri   rn   rj   oxoya1a2s          r)   ro   z3test_agg_filter.<locals>.OffsetFilter.process_image~   sU    \\FBSb3%7a@Bc"r'C-00q9BIr+   N)r   rv   rw   rx   r   rk   ro   rg   r+   r)   OffsetFilterr{   v   s    	#	5	r+   r   c                   *    e Zd ZdZddZd Z fdZy)'test_agg_filter.<locals>.GaussianFilterzSimple Gaussian filter.c                 .    || _         || _        || _        y r}   )rb   alphacolor)ri   rb   r   r   s       r)   r   z0test_agg_filter.<locals>.GaussianFilter.__init__   s    DJDJDJr+   c                 >    t        | j                  dz  dz  |z        S Nr   r   )r_   rb   rh   s     r)   rk   z/test_agg_filter.<locals>.GaussianFilter.get_pad   s    tzz!|b(3.//r+   c                     t        j                  |      }| j                  |d d d d d df<    |d d d d df   | j                  z  | j                  dz  |z        |d d d d df<   |S r   )r?   
empty_liker   r   rb   )ri   rn   rj   rt   rc   s       r)   ro   z5test_agg_filter.<locals>.GaussianFilter.process_image   sk    j1I"&**IaBQBh!)*Q1W*=

*J*.**r/C*?"AIaAgr+   N)      ?r   r   r   )rv   rw   rx   __doc__r   rk   ro   )rc   s   r)   GaussianFilterr      s    %	
	0	r+   r   c                   (    e Zd Zd fd	Zd Zd Zy))test_agg_filter.<locals>.DropShadowFilterc                 >     |||      | _          |      | _        y r}   )gauss_filteroffset_filter)ri   rb   r   r   r~   r   r   s        r)   r   z2test_agg_filter.<locals>.DropShadowFilter.__init__   s!     .ueU CD!-g!6Dr+   c                 ~    t        | j                  j                  |      | j                  j                  |            S r}   )r^   r   rk   r   rh   s     r)   rk   z1test_agg_filter.<locals>.DropShadowFilter.get_pad   s6    t((005))11#68 8r+   c                 v    | j                   j                  ||      }| j                  j                  ||      }|S r}   )r   ro   r   )ri   rn   rj   t1t2s        r)   ro   z7test_agg_filter.<locals>.DropShadowFilter.process_image   s7    ""00SAB##11"c:BIr+   N)g333333?r   r   r   )r   r   s   r)   DropShadowFilterr      s    	7	8	r+   r   )皙?r   ?)r   r   r   zbo-brZ   r-   r.   zLine 1)mecmfclwmewmslabel)r   g?gffffff?zro-r   g      @g      rL   )rW   r[   unitsr   Tr   r   F)r   )r0   r1   rK   	get_xdata	get_ydataupdate_frommtransformsoffset_copyget_transformfigureset_transform
set_zorder
get_zorderset_agg_filterset_rasterizedr4   set_ylimxaxisset_visibleyaxis)ry   r   r'   r7   line1line2gausslinexxyyshadow	transformr   r   r\   rc   s               @@@@r)   test_agg_filterr   W   s   -) )z  $:  llnGC WW_ou#!r  KFEWW_ou#!r  KFE QE $ ^^^^''"b/4   ++D,>,>,@")).1TK	Y' 	$//+c12e$d##$& KKBKKBHHHHr+   c                      t        j                  d      } t        j                         }t	        j
                  t              5  | j                  |       d d d        y # 1 sw Y   y xY w)N)i,  r;   )figsize)r0   r   r!   r"   pytestraises
ValueErrorr#   )r'   r5   s     r)   test_too_large_imager      sH    
**[
)C::<D	z	" D  s   AA(c                     t        d      } t        j                         \  }}|j                  | t	        j
                  |              |j                  j                          t        j                         \  }}dt        d<   |j                  | t	        j
                  |              |j                  j                          y )N   i   agg.path.chunksize)	ranger0   r1   rK   r?   sincanvasdrawr
   )rW   r'   r7   s      r)   test_chunksizer      s    c
A llnGCGGArvvayJJOO llnGC%(H!"GGArvvayJJOOr+   Aggc                      t        j                  g dg d       t        j                         } t        j                  | dd       t        j                  |       }|j                  d   dk(  sJ y )Nr   r   rH   r   r   r   jpgr   )r>   rj   rj   )r   r   )r0   rK   r!   r"   r#   r   openinfor(   rs   s     r)   test_jpeg_dpir      sP     HHY	"
**,CKKEs+	CB775>Z'''r+   c                     ddl m}  t        j                         } |        }|j	                  dd       t        j                         j                  |dd|i       t        j                  |      }|j                  d   dk(  sJ y )Nr   )PngInfoSoftwaretestr<   pnginfor>   
pil_kwargs)PIL.PngImagePluginr   r!   r"   add_textr0   r   r#   r   r   r   )r   r(   r   rs   s       r)   test_pil_kwargs_pngr      sk    *
**,CiGZ(JJLU	77KL	CB77:&(((r+   c                  Z   t        j                         } ddi}t        j                         j	                  | d|       t        j                  |       }|j                  j                         D ci c]#  \  }}t        j                  |   j                  |% }}}|d   dk(  sJ y c c}}w )Ndescriptionz
test imagetiffr   ImageDescription)r!   r"   r0   r   r#   r   r   tag_v2itemsr   TAGS_V2name)r(   r   rs   kvtagss         r)   test_pil_kwargs_tiffr      s    
**,C.JJJLV
C	CB46IIOO4EFDAqHQ$$a'FDF"#|333 Gs   1(B'c                     t        j                  g dg d       t        j                         } ddi}t        j                  | d|       t        |      dk(  sJ t        j                         }ddi}t        j                  |d|       t        |      dk(  sJ |j                         j                  | j                         j                  kD  sJ y )Nr   r   qualityr   webpr   d   )r0   rK   r!   r"   r#   len	getbuffernbytes)	buf_smallpil_kwargs_low	buf_largepil_kwargs_highs       r)   test_pil_kwargs_webpr      s    HHY	"

I^NKK	&^D~!###

I #&OKK	&_E1$$$ '')*=*=*?*F*FFFFr+   c                      t        j                  g dg d       t        j                         } t        j                  | dd       t        j                  |       }|j                  dk(  sJ y )Nr   r   r   T)r>   transparentRGBA)r0   rK   r!   r"   r#   r   r   rR   r   s     r)   test_webp_alphar  	  sJ    HHY	"
**,CKKF5	CB77fr+   c                     t        j                         \  } }|j                  dgdg      j                  t	        ddg             t        j                  t              5  | j                  j                          d d d        y # 1 sw Y   y xY w)Nr   )r   r   )rH   r   )
r0   r1   scatter	set_pathsr   r   r   	TypeErrorr   r   )r'   r7   s     r)   (test_draw_path_collection_error_handlingr	    sg    llnGCJJsQC""4(8#9:	y	! 

  s   BBc                     d} d}d|z  }d|z  }t        j                  d||       }t        j                  |       |z  }d|d d d<   t        t        j                  ||f      j
                        }d|_        t        |||      }|j                         }|j                  d       |j                  d       |j                  d	       t        j                  t        d
      5  |j                  ||t!                      d d d        |j                  d        t        j                  t        d      5  |j                  ||t!               d       d d d        t#        ddi      5  t        j                  t        d      5  |j                  ||t!                      d d d        d d d        t#        ddi      5  t        j                  t        d      5  |j                  ||t!                      d d d        d d d        t#        ddi      5  t        j                  t        d      5  |j                  ||t!                      d d d        d d d        d|_        t        j                  t        d      5  |j                  ||t!                      d d d        y # 1 sw Y   xY w# 1 sw Y   ]xY w# 1 sw Y   xY w# 1 sw Y   "xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NrG   i  r-      r   rH   r   r   /zcannot split hatched path)matchzcannot split filled path)r   r   r   r   z
Please seti@B zPlease reducei_ Fzshould_simplify is False)r?   linspacerJ   r   vstackTsimplify_thresholdr   new_gcset_linewidthset_foreground	set_hatchr   r   OverflowError	draw_pathr   r   should_simplify)	Nrj   rZ   hrW   r[   pathragcs	            r)   test_chunksize_failsr    s    	A
C	#A	#A 	Aq!A

QAAccF		1a&!##$DD 
Q3	B	BQcLL	},G	H 4
R0234LL	},F	G ?
R02I>? 
)1-	. 8]]== 	8LLT#4#67	88
 
)95	6 8]]=@ 	8LLT#4#67	88
 
)62	3 8]]=@ 	8LLT#4#67	88 !D	},F	G 4
R0234 4/4 4? ?
	8 	88 8	8 	88 8	8 	88 8
4 4s   "J2J*$K J7K9KK1KK5*K)K58LJ'*J47K	<KKK	KK&)K2	.K55K>L
c                      t        j                         } | j                  d      j                  g dg dt	        j
                  d      g       | j                  j                          y )N3d)
projectionr   r   )	linewidth)path_effects)r0   r   add_subplotr  r   Stroker   r   )r'   s    r)   test_non_tuple_rgbafacer&  M  sO    
**,COOtO$,,9K,>,>,K+L - NJJOOr+   )/r!   numpyr?   numpy.testingr   PILr   r   r   
matplotlibr   r   r   r0   r	   r   r
   r   matplotlib.backends.backend_aggr   matplotlib.figurer   matplotlib.imager   matplotlib.pathr   matplotlib.testing.decoratorsr   matplotlib.transformsr   r*   r9   rE   rM   r   r   r   markbackendr   r   r   r   r  r	  r  r&  rg   r+   r)   <module>r3     s    	  3    8 $ #   : 3)>	#$ #$$7n  8n b U( ()4
G24jr+   