
    gK                        d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZ ddlmZ erdd	lmZ dd
lmZ  G d d      Z	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)z/Streamlit support for Matplotlib PyPlot charts.    )annotationsN)TYPE_CHECKINGAnycast)show_deprecation_warning)WidthBehaviormarshall_images)	ImageList)gather_metrics)Figure)DeltaGeneratorc                  V    e Zd Z ed      	 	 	 d	 	 	 	 	 	 	 	 	 dd       Zedd       Zy)PyplotMixinpyplotNc                    |st        d       t               }t        | j                  j	                         ||||fi | | j                  j                  d|      S )a,	  Display a matplotlib.pyplot figure.

        .. Important::
            You must install ``matplotlib`` to use this command.

        Parameters
        ----------
        fig : Matplotlib Figure
            The Matplotlib ``Figure`` object to render. See
            https://matplotlib.org/stable/gallery/index.html for examples.

            .. note::
                When this argument isn't specified, this function will render the global
                Matplotlib figure object. However, this feature is deprecated and
                will be removed in a later version.

        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
            Whether to override the figure's native width with the width of
            the parent container. If ``use_container_width`` is ``True``
            (default), Streamlit sets the width of the figure to match the
            width of the parent container. If ``use_container_width`` is
            ``False``, Streamlit sets the width of the chart to fit its
            contents according to the plotting library, up to the width of the
            parent container.

        **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

        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.

        a%  
Calling `st.pyplot()` without providing a figure argument has been deprecated
and will be removed in a later version 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)
```

If you have a specific use case that requires this functionality, please let us
know via [issue on Github](https://github.com/streamlit/streamlit/issues).
imgs)r   ImageListProtomarshalldg_get_delta_path_str_enqueue)selffigclear_figureuse_container_widthkwargsimage_list_protos         N/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/pyplot.pyr   zPyplotMixin.pyplot"   sh    N $ & $ *+GG'')	
 	
 ww(899    c                    t        d|       S )zGet our DeltaGenerator.r   )r   )r   s    r   r   zPyplotMixin.dg   s     $d++r   )NNT)
r   Figure | Noner   bool | Noner   boolr   r   returnr   )r$   r   )__name__
__module____qualname__r   r   propertyr    r   r   r   r   !   sp    H "$($(	b:b: "b: "	b:
 b: 
b: b:H , ,r   r   c           
        	 dd l m} |j                          |s|d}t	        d|      }dddd}|j                         D 	ci c]  \  }}	||j                  ||	       }}}	|j                  |       t        j                         }
 |j                  |
fi | |rt        j                  nt        j                  }t        | |
d ||d	d
d       |r|j                          y y # t        $ r t        d      w xY wc c}	}w )Nr   z$pyplot() command requires matplotlibTr   tight   png)bbox_inchesdpiformatFRGBPNG)coordinatesimagecaptionwidth
proto_imgsclampchannelsoutput_format)matplotlib.pyplotr   ioffImportErrorr   itemsgetupdateioBytesIOsavefigr   COLUMNORIGINALr	   clf)r3   r   r   r   r   r   pltoptionsabr4   image_widths               r   r   r      s
   B'
 L8S!
 &cUCG 07}}?tq!q&**Q""G?
MM'JJLECKK   39O9O  #	 	 Q  B@AAB$ @s   C$ C<$C9)NTT)r3   strr   r   r   r!   r   r"   r   r#   r   r   r$   None)__doc__
__future__r   rA   typingr   r   r   streamlit.deprecation_utilr   "streamlit.elements.lib.image_utilsr   r	   streamlit.proto.Image_pb2r
   r   streamlit.runtime.metrics_utilr   matplotlib.figurer   streamlit.delta_generatorr   r   r   r)   r   r   <module>rW      s    6 " 	 + + ? M A 9(8i, i,^  $ $55$5 
5 	5
 5 5 
5r   