
    IR-eC-                        d dl Z d dlZd dlmZ d dlZd dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ g dZ G d d	          Z G d
 de          Z G d dee j                  Z G d de          Z G d de          Z G d de          ZdS )    N)OrderedDict)rcParams)Line2DPath)	PathPatch)AstropyDeprecationWarning)RectangularFrame1DSpine	BaseFrameRectangularFrameEllipticalFramec                       e Zd ZdZdddZed             Zej        d             Zd Zed             Z	e	j        d	             Z	ed
             Z
e
j        d             Z
d Zd ZdS )r
   a  
    A single side of an axes.

    This does not need to be a straight line, but represents a 'side' when
    determining which part of the frame to put labels and ticks on.

    Parameters
    ----------
    parent_axes : `~astropy.visualization.wcsaxes.WCSAxes`
        The parent axes
    transform : `~matplotlib.transforms.Transform`
        The transform from data to world
    data_func : callable
        If not ``None``, it should be a function that returns the appropriate spine
        data when called with this object as the sole argument.  If ``None``, the
        spine data must be manually updated in ``update_spines()``.
    N)	data_funcc                L    || _         || _        || _        d | _        d | _        d S N)parent_axes	transformr   _data_world)selfr   r   r   s       Clib/python3.11/site-packages/astropy/visualization/wcsaxes/frame.py__init__zSpine.__init__+   s*    &""
    c                 `    | j         !| j        r|                     |           | _        | j         S r   )r   r   datar   s    r   r   z
Spine.data3   s,    :$.t,,DIzr   c                     || _         |	d | _        d S t          j        d          5  | j                            | j                   | _        d d d            n# 1 swxY w Y   |                                  d S )Nignoreinvalidr   r   nperrstater   _update_normalr   values     r   r   z
Spine.data9   s    
=DKKKX... C C"n66tzBBC C C C C C C C C C C C C C C!!!!!s   %AA Ac                 J    | j         j                            | j                  S r   )r   	transDatar   r   r   s    r   
_get_pixelzSpine._get_pixelC   s    )33DJ???r   c                 ^    t          j        dt                     |                                 S )NzPixel coordinates cannot be accurately calculated unless Matplotlib is currently drawing a figure, so the .pixel attribute is deprecated and will be removed in a future astropy release.)warningswarnr   r)   r   s    r   pixelzSpine.pixelF   s2     &	
 	
 	
    r   c                 :    t          j        dt                     d S )Na  Manually setting pixel values of a Spine can lead to incorrect results as these can only be accurately calculated when Matplotlib is drawing a figure. As such the .pixel setter now does nothing, is deprecated, and will be removed in a future astropy release.)r+   r,   r   r%   s     r   r-   zSpine.pixelQ   s*    ? &	
 	
 	
 	
 	
r   c                     | j         S r   )r   r   s    r   worldzSpine.world[   s
    {r   c                     || _         |d | _        d | _        d S | j                            |          | _        | j        j                            | j                  | _        |                                  d S r   )r   r   _pixelr   r   r(   r$   r%   s     r   r0   zSpine.world_   sl    =DJDKKK11%88DJ*4>>tzJJDK!!!!!r   c                     |                                  }|dd df         |d ddf         z
  }|dd df         |d ddf         z
  }t          j        t          j        ||                     | _        d S )N   r   )r)   r"   degreesarctan2normal_angle)r   r-   dxdys       r   r$   zSpine._update_normalj   s{    !!122q5\E#2#q&M)122q5\E#2#q&M)Jrz"rc':':;;r   c                    |                                  }|dddf         |dddf         }}t          j        dt          j        t          j        t          j        |          dz  t          j        |          dz  z                       g          }t          j        |d         dz  ||          }t          j        |d         dz  ||          }t          j        ||d         dz            dz
  }| j        |         dz   }|||fS )	zO
        Return the x, y, normal_angle values halfway along the spine.
        Nr   r4              r5   g       @g     f@)	r)   r"   hstackcumsumsqrtdiffinterpsearchsortedr8   )	r   r-   x_dispy_dispdxcenyceniminr8   s	            r   _halfway_x_y_anglezSpine._halfway_x_y_angleq   s     !!qqq!teAAAqDkI")BGBGFOOq$8276??a;O$OPPQQR
 
 y2a00y2a00 q!B%#+..2 (.6T<''r   )__name__
__module____qualname____doc__r   propertyr   setterr)   r-   r0   r$   rJ    r   r   r
   r
      s        $ =A        X
 
[" " ["@ @ @ ! ! X! \
 
 \
   X \" " \"< < <( ( ( ( (r   r
   c                   H    e Zd ZdZed             Zej        d             ZdS )SpineXAlignedz
    A single side of an axes, aligned with the X data axis.

    This does not need to be a straight line, but represents a 'side' when
    determining which part of the frame to put labels and ticks on.
    c                     | j         S r   )r   r   s    r   r   zSpineXAligned.data   s
    zr   c                    || _         |	d | _        d S t          j        d          5  | j                            | j         d d ddf                   | _        d d d            n# 1 swxY w Y   |                                  d S )Nr   r   r   r4   r!   r%   s     r   r   zSpineXAligned.data   s    
=DKKKX... K K"n66tz!!!QqS&7IJJK K K K K K K K K K K K K K K!!!!!s   1A%%A),A)N)rK   rL   rM   rN   rO   r   rP   rQ   r   r   rS   rS      sV            X 
[" " [" " "r   rS   c                        e Zd ZdZeZd fd	Zed             Zed             Z	e	j
        d             Z	d Zed             Zd	 Zd
 Zd Zd Zd Zd Zd Z xZS )r   z|
    Base class for frames, which are collections of
    :class:`~astropy.visualization.wcsaxes.frame.Spine` instances.
    Nc                     t                                                       || _        || _        t          d         | _        t          d         | _        || _        | j        D ]}| 	                    ||          | |<   d S )Nzaxes.linewidthzaxes.edgecolor)
superr   r   
_transformr   
_linewidth_color_pathspine_namesspine_class)r   r   r   pathaxis	__class__s        r   r   zBaseFrame.__init__   s    &#"#34/0
$ 	B 	BD))+yAADJJ	B 	Br   c                 N    | j                                         \  }}||k     rdndS )Nlowerupper)r   get_ylim)r   yminymaxs      r   originzBaseFrame.origin   s,    %..00
d++ww72r   c                     | j         S r   )rY   r   s    r   r   zBaseFrame.transform   s
    r   c                 8    || _         | D ]}|| |         _        d S r   )rY   r   )r   r&   r`   s      r   r   zBaseFrame.transform   s1     	) 	)D#(DJ  	) 	)r   c                    |                                   g g }}| j        D ]V}|                    | |         j        d d df                    |                    | |         j        d d df                    Wt	          j        t	          j        |          t	          j        |          g                                          }| j        t          |          | _        d S || j        _
        d S )Nr   r4   )update_spinesr]   appendr   r"   vstackr>   	transposer\   r   vertices)r   xyr`   rp   s        r   _update_patch_pathzBaseFrame._update_patch_path   s    21$ 	, 	,DHHT$Z_QQQT*+++HHT$Z_QQQT*++++9billBIaLL9::DDFF:hDJJJ"*DJr   c                     |                                   t          | j        | j        j        t
          d         d          S )Nzaxes.facecolorwhite)r   	facecolor	edgecolor)rs   r   r\   r   r(   r   r   s    r   patchzBaseFrame.patch   sE    !!!J&0/0	
 
 
 	
r   c                     | D ]g}| |                                          }|d d df         |d d df         }}t          ||| j        | j        d          }|                    |           hd S )Nr   r4     	linewidthcolorzorderr)   r   rZ   r[   draw)r   rendererr`   r-   rq   rr   lines          r   r   zBaseFrame.draw   s     	  	 DJ))++EA;aaadqA1t{4  D IIh	  	 r   c                    |                                   t                      }| D ]}| |         j        }|                     | j        | j                  ||<   |j        dk    r{t          j        dd|j	        d                   t          j        dd|          t          j
        fd|j        D                                                       ||         _        |||         _        |S )Nr   r<   g      ?c                 <    g | ]}t          j        |          S rQ   )r"   rB   ).0rF   pp_news     r   
<listcomp>z$BaseFrame.sample.<locals>.<listcomp>   s'    <<<RYua++<<<r   )rl   r   r   r^   r   r   sizer"   linspaceshapearrayTro   )r   	n_samplesspinesr`   r   r   r   s        @@r   samplezBaseFrame.sample   s     
	) 
	)D:?D++D,<dnMMF4Ly1}}KS$*Q-88Ci88$&H<<<<<TV<<<% %)++ t!! %)t!!r   c                     || _         dS )z
        Sets the color of the frame.

        Parameters
        ----------
        color : str
            The color of the frame.
        Nr[   )r   r}   s     r   	set_colorzBaseFrame.set_color   s     r   c                     | j         S r   r   r   s    r   	get_colorzBaseFrame.get_color   s
    {r   c                     || _         dS )z
        Sets the linewidth of the frame.

        Parameters
        ----------
        linewidth : float
            The linewidth of the frame in points.
        NrZ   )r   r|   s     r   set_linewidthzBaseFrame.set_linewidth  s     $r   c                     | j         S r   r   r   s    r   get_linewidthzBaseFrame.get_linewidth  s
    r   c                 v    |                                  D ]#}|j        r|                    |          |_        $d S r   )valuesr   r   )r   spines     r   rl   zBaseFrame.update_spines  sA    [[]] 	4 	4E 4"__U33
	4 	4r   r   )rK   rL   rM   rN   r
   r^   r   rO   rh   r   rP   rs   rx   r   r   r   r   r   r   rl   __classcell__ra   s   @r   r   r      s<        
 K
B 
B 
B 
B 
B 
B 3 3 X3   X ) ) )
+ + + 
 
 X
       &	 	 	  	$ 	$ 	$  4 4 4 4 4 4 4r   r   )	metaclassc                   6     e Zd ZdZdZeZ fdZd Zd Z	 xZ
S )r	   &
    A classic rectangular frame.
    btc                 L   | j                                         \  }}| j                                         \  }}t          j        ||g||gf          | d         _        t          j        ||g||gf          | d         _        t                                                       d S )Nbtr   get_xlimre   r"   r   r   rX   rl   r   xminxmaxrf   rg   ra   s        r   rl   z RectangularFrame1D.update_spines  s    %..00
d%..00
dD$<$">??S	D$<$">??S	r   c                    |                                   | j                                        \  }}| j                                        \  }}|||||g}|||||g}t	          j        t	          j        |          t	          j        |          g                                          }| j        t          |          | _        d S || j        _
        d S r   )rl   r   r   re   r"   rn   r>   ro   r\   r   rp   )r   r   r   rf   rg   rq   rr   rp   s           r   rs   z%RectangularFrame1D._update_patch_path&  s    %..00
d%..00
d4tT*4tT*9billBIaLL9::DDFF:hDJJJ"*DJr   c                    | j                                         \  }}| j                                         \  }}|||||g}|||||g}t          ||| j        | j        d| j         j                  }|                    |           d S )Nrz   )r|   r}   r~   r   )r   r   re   r   rZ   r[   r(   r   )	r   r   r   r   rf   rg   rq   rr   r   s	            r   r   zRectangularFrame1D.draw6  s    %..00
d%..00
d4tT*4tT*o+&0
 
 
 			(r   )rK   rL   rM   rN   r]   rS   r^   rl   rs   r   r   r   s   @r   r	   r	     sl          KK         + + +       r   r	   c                   &     e Zd ZdZdZ fdZ xZS )r   r   brtlc                    | j                                         \  }}| j                                         \  }}t          j        ||g||gf          | d         _        t          j        ||g||gf          | d         _        t          j        ||g||gf          | d         _        t          j        ||g||gf          | d         _        t                                                       d S )Nr   rr   lr   r   s        r   rl   zRectangularFrame.update_spinesO  s    %..00
d%..00
dD$<$">??S	D$<$">??S	D$<$">??S	D$<$">??S	r   )rK   rL   rM   rN   r]   rl   r   r   s   @r   r   r   H  sI          K	  	  	  	  	  	  	  	  	 r   r   c                   2     e Zd ZdZdZ fdZd Zd Z xZS )r   z
    An elliptical frame.
    chvc                 `   | j                                         \  }}| j                                         \  }}d||z   z  }d||z   z  }||z
  }||z
  }t          j        ddt          j        z  d          }	t          j        ||t          j        |	          z  z   ||t          j        |	          z  z   g          	                                | d         _
        t          j        t          j        ||d          t          j        |d          g          	                                | d         _
        t          j        t          j        |d          t          j        ||d          g          	                                | d         _
        t                                                       d S )Ng      ?r<   r=   rz   chv)r   r   re   r"   r   pir   cossinro   r   repeatrX   rl   )r   r   r   rf   rg   xmidymidr9   r:   thetara   s             r   rl   zEllipticalFrame.update_spinesb  su   %..00
d%..00
ddTk"dTk"D[D[CRUD11B&&rBF5MM/A(AB
 

)++ 	S	 [tT**BIdD,A,AB
 

)++ 	S	 YtT""BKdD$A$AB
 

)++ 	S	 	r   c                     |                                   | d         j        }| j        t          |          | _        dS || j        _        dS )zsOverride path patch to include only the outer ellipse,
        not the major and minor axes in the middle.
        r   N)rl   r   r\   r   rp   )r   rp   s     r   rs   z"EllipticalFrame._update_patch_pathy  sJ     	9>:hDJJJ"*DJr   c                     d}| |                                          }t          |dddf         |dddf         | j        | j        d          }|                    |           dS )zOverride to draw only the outer ellipse,
        not the major and minor axes in the middle.

        FIXME: we may want to add a general method to give the user control
        over which spines are drawn.
        r   Nr   r4   rz   r{   r   )r   r   r`   r-   r   s        r   r   zEllipticalFrame.draw  sw     T
%%''!!!Q$K!!!Q$Ko+
 
 
 			(r   )	rK   rL   rM   rN   r]   rl   rs   r   r   r   s   @r   r   r   [  sg          K         .
+ 
+ 
+      r   r   )abcr+   collectionsr   numpyr"   
matplotlibr   matplotlib.linesr   r   matplotlib.patchesr   astropy.utils.exceptionsr   __all__r
   rS   ABCMetar   r	   r   r   rQ   r   r   <module>r      s   


  # # # # # #           ) ) ) ) ) ) ) ) ( ( ( ( ( ( > > > > > >  k( k( k( k( k( k( k( k(\" " " " "E " " ".u4 u4 u4 u4 u4s{ u4 u4 u4 u4p0 0 0 0 0 0 0 0f         y      &: : : : :i : : : : :r   