
    &e                     <   U d Z ddlZddlmZmZmZmZ ddlmZ ddl	m
c 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 erdd
lmZ ddlmZ  ee          Zeed<    G d d          Z	 	 	 dde deded         dee!         de!deddfdZ" G d de          Z#dS )z/Streamlit support for Matplotlib PyPlot charts.    N)TYPE_CHECKINGAnyOptionalcast)Final)config)StreamlitDeprecationWarning)
get_logger)	ImageList)gather_metrics)Figure)DeltaGeneratorLOGGERc                       e Zd Z ed          	 	 	 dded         dee         deded	d
f
d            Zedd            Z	dS )PyplotMixinpyplotNTfigr   clear_figureuse_container_widthkwargsreturnr   c                    |s:t          j        d          r&| j                            t	                                 t                      }t          | j                                        ||||fi | | j                            d|          S )a  Display a matplotlib.pyplot figure.

        Parameters
        ----------
        fig : Matplotlib Figure
            The figure to plot. When this argument isn't specified, this
            function will render the global figure (but this is deprecated,
            as described below)

        clear_figure : bool
            If True, the figure will be cleared after being rendered.
            If False, the figure will not be cleared after being rendered.
            If left unspecified, we pick a default based on the value of `fig`.

            * If `fig` is set, defaults to `False`.

            * If `fig` is not set, defaults to `True`. This simulates Jupyter's
              approach to matplotlib rendering.

        use_container_width : bool
            If True, set the chart width to the column width. Defaults to `True`.

        **kwargs : any
            Arguments to pass to Matplotlib's savefig function.

        Example
        -------
        >>> import streamlit as st
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>>
        >>> arr = np.random.normal(1, 1, size=100)
        >>> fig, ax = plt.subplots()
        >>> ax.hist(arr, bins=20)
        >>>
        >>> st.pyplot(fig)

        .. output::
           https://doc-pyplot.streamlit.app/
           height: 630px

        Notes
        -----
        .. note::
           Deprecation warning. After December 1st, 2020, we will remove the ability
           to specify no arguments in `st.pyplot()`, as that requires the use of
           Matplotlib's global figure object, which is not thread-safe. So
           please always pass a figure object as shown in the example section
           above.

        Matplotlib supports several types of "backends". If you're getting an
        error using Matplotlib with Streamlit, try setting your backend to "TkAgg"::

            echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc

        For more information, see https://matplotlib.org/faq/usage_faq.html.

        deprecation.showPyplotGlobalUseimgs)	r   
get_optiondg	exceptionPyplotGlobalUseWarningImageListProtomarshall_get_delta_path_str_enqueue)selfr   r   r   r   image_list_protos         9lib/python3.11/site-packages/streamlit/elements/pyplot.pyr   zPyplotMixin.pyplot&   s    F  	8v()JKK 	8G466777)++G''))	
 	
 	
 	
 	
 w(8999    c                 "    t          d|           S )zGet our DeltaGenerator.r   )r   r#   s    r%   r   zPyplotMixin.dgw   s     $d+++r&   )NNT)r   r   )
__name__
__module____qualname__r   r   boolr   r   propertyr    r&   r%   r   r   %   s        ^H #''+$(	N: N:hN: tnN: "	N:
 N: 
N: N: N: N:` , , , X, , ,r&   r   Tcoordinatesr$   r   r   r   r   r   r   c           
         	 dd l }dd lm} |                                 n# t          $ r t	          d          w xY w|s|d}t          d|          }dddd}fd	|                                D             }                    |           t          j	                    }	 |j
        |	fi  |rt          j        j        nt          j        j        }
t          j        | |	d |
|d
dd           |r|                                 d S d S )Nr   z$pyplot() command requires matplotlibTr   tight   png)bbox_inchesdpiformatc                 D    i | ]\  }}|                     ||          S r.   )get).0abr   s      r%   
<dictcomp>zmarshall.<locals>.<dictcomp>   s-    ???tq!q&**Q""???r&   FRGBPNG)r/   imagecaptionwidth
proto_imgsclampchannelsoutput_format)
matplotlibmatplotlib.pyplotr   ioffImportErrorr   itemsupdateioBytesIOsavefigimage_utilsWidthBehaviourCOLUMNORIGINALmarshall_imagesclf)r/   r$   r   r   r   r   rF   pltoptionsr?   image_widths        `     r%   r    r    }   sp   B''''''



 B B B@AAAB
  "L8S!!
 &cUCCG @???w}}???G
MM'JLLECK      	1"))'0 
 #	 	 	 	  					 s   " <c                   ,     e Zd Zd fdZdefdZ xZS )r   r   Nc                     t          t          |                               |                                 d           d S )Nr   )msgconfig_option)superr   __init___get_message)r#   	__class__s    r%   r]   zPyplotGlobalUseWarning.__init__   sG    $d++44!!##3T 	5 	
 	
 	
 	
 	
r&   c                     dS )Na  
You are calling `st.pyplot()` without any arguments. After December 1st, 2020,
we will remove the ability to do this as it requires the use of Matplotlib's global
figure object, which is not thread-safe.

To future-proof this code, you should pass in a figure as shown below:

```python
>>> fig, ax = plt.subplots()
>>> ax.scatter([1, 2, 3], [1, 2, 3])
>>>    ... other plotting actions ...
>>> st.pyplot(fig)
```
r.   r(   s    r%   r^   z#PyplotGlobalUseWarning._get_message   s     r&   )r   N)r)   r*   r+   r]   strr^   __classcell__)r_   s   @r%   r   r      sX        
 
 
 
 
 

c        r&   r   )NTT)$__doc__rL   typingr   r   r   r   typing_extensionsr   streamlit.elements.imageelementsr?   rO   	streamlitr   streamlit.errorsr	   streamlit.loggerr
   streamlit.proto.Image_pb2r   r   streamlit.runtime.metrics_utilr   matplotlib.figurer   streamlit.delta_generatorr   r)   r   __annotations__r   ra   r,   r    r   r.   r&   r%   <module>rp      s   6 5 5 				 5 5 5 5 5 5 5 5 5 5 5 5 # # # # # # . . . . . . . . .       8 8 8 8 8 8 ' ' ' ' ' ' A A A A A A 9 9 9 9 9 9 9((((((888888
8$$ $ $ $U, U, U, U, U, U, U, U,v ##' $8 88$8 
(	8 4.	8
 8 8 
8 8 8 8v    8     r&   