L i dZddlmZddlZddlmZmZmZddlm Z m Z ddl m Z ddl mZmZmZddlmZdd lmZer dd lmZdd lmZGd d Z d ddZy)z/Streamlit support for Matplotlib PyPlot charts.) annotationsN) TYPE_CHECKINGAnycast)make_deprecated_name_warningshow_deprecation_warning)marshall_images) LayoutConfigWidthvalidate_width) ImageList)gather_metrics)Figure)DeltaGeneratorc`eZdZed dddd ddZed dZy) PyplotMixinpyplotNstretch)widthuse_container_widthc 4|!ttdddddd|rdnd }|s td t|d t| }t }t |j j||||fi||j jd||S)a Display a matplotlib.pyplot figure. .. Important:: You must install ``matplotlib>=3.0.0`` to use this command. You can install all charting dependencies (except Bokeh) as an extra with Streamlit: .. code-block:: shell pip install streamlit[charts] 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. width : "stretch", "content", or int The width of the chart element. This can be one of the following: - ``"stretch"`` (default): The width of the element matches the width of the parent container. - ``"content"``: The width of the element matches the width of its content, but doesn't exceed the width of the parent container. - An integer specifying the width in pixels: The element has a fixed width. If the specified width is greater than the width of the parent container, the width of the element matches the width of the parent container. 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. .. deprecated:: ``use_container_width`` is deprecated and will be removed in a future release. For ``use_container_width=True``, use ``width="stretch"``. For ``use_container_width=False``, use ``width="content"``. **kwargs : any Arguments to pass to Matplotlib's savefig function. Example ------- >>> import matplotlib.pyplot as plt >>> import streamlit as st >>> from numpy.random import default_rng as rng >>> >>> arr = rng(0).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. rrz 2025-12-31znFor `use_container_width=True`, use `width='stretch'`. For `use_container_width=False`, use `width='content'`.F)include_st_prefix)show_in_browserrcontenta% 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). T) allow_content)rimgs) layout_config) rrr r ImageListProtomarshalldg_get_delta_path_str_enqueue)selffig clear_figurerrkwargsrimage_list_protos _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/elements/pyplot.pyrzPyplotMixin.pyplot&sD  * $,) N&+ !& "5I)E $& $ uD1$51 )+ GG ' ' )        ww(8 VVctd|S)zGet our DeltaGenerator.r)r)r#s r(r zPyplotMixin.dgs$d++r))NN) r$ Figure | Noner% bool | Nonerr rr,r&rreturnr)r-r)__name__ __module__ __qualname__rrpropertyr r)r(rr%sH"$(OW !+/ OW OW"OW  OW ) OWOW OWOWb,,r)rc  ddlm}|j|s|d}t d|}dddd}|j D cic]\}} ||j || }}} |j|tj} |j| fi|t|| d||d d d |r|jyy#t$r tdwxYwcc} }w) Nrz$pyplot() command requires matplotlibTrtightpng) bbox_inchesdpiformatFRGBPNG) coordinatesimagecaptionr proto_imgsclampchannels output_format) matplotlib.pyplotrioff ImportErrorritemsgetupdateioBytesIOsavefigr clf) r<r'rr$r%r&pltoptionsabr=s r(rrsB'    L8S! &cUCG07}}?tq!q&**Q""?G? MM' JJLECKK  ##   K B@AAB$@sCCC)NT)r<strr'rrr r$r+r%r,r&rr-None)__doc__ __future__rrItypingrrrstreamlit.deprecation_utilrr"streamlit.elements.lib.image_utilsr #streamlit.elements.lib.layout_utilsr r r streamlit.proto.Image_pb2r rstreamlit.runtime.metrics_utilrmatplotlib.figurerstreamlit.delta_generatorrrrr2r)r(r]s6" ++?SSA9(8V,V,z $ 22$2 2  2  2  2 2r)