
    Wi                         d dl Zd dlmZ d dlmZ 	 	 	 	 	 ddej                  dedee	e
f   de
deded	ej                  fd
Zy)    N)Unionprobabilitiesmin_probabilitycustom_labelstitlewidthheightreturnc                    t        |j                        dk7  rt        d      t        |||kD           dk(  rt        d      t        j                  ||k\        j                         }||   j                         }t        |t              r|D 	cg c]#  }	t        |	      dgg| j                  |   |	   z   % }
}	|
D cg c]'  }dj                  |dd D cg c]  }|d   	 c}      ) }
}}|
D cg c]  }t        |      dk  r|n|dd	 d
z    }
}n| j                  ,|r*|D cg c]  }| j                  || j                  z        }
}ng }
|D ]  }| j                  |      }|rV|dd D cg c]  }|d   	 }}d| ddj                  |       }t        |      dkD  r|dd d
z   n|}|
j                  |       l|j                  ||           t!        j"                  t!        j$                  ||
t'        dt'        dd            d            }|j)                  d| ddddt'        dd      dd||t'        dd d!"      #       |S c c}	w c c}w c c}}w c c}w c c}w c c}w )$ay  Visualize the distribution of topic probabilities.

    Arguments:
        topic_model: A fitted BERTopic instance.
        probabilities: An array of probability scores
        min_probability: The minimum probability score to visualize.
                         All others are ignored.
        custom_labels: If bool, whether to use custom topic labels that were defined using
                       `topic_model.set_topic_labels`.
                       If `str`, it uses labels from other aspects, e.g., "Aspect1".
        title: Title of the plot.
        width: The width of the figure.
        height: The height of the figure.

    Examples:
    Make sure to fit the model before and only input the
    probabilities of a single document:

    ```python
    topic_model.visualize_distribution(probabilities[0])
    ```

    Or if you want to save the resulting figure:

    ```python
    fig = topic_model.visualize_distribution(probabilities[0])
    fig.write_html("path/to/file.html")
    ```
    <iframe src="../../getting_started/visualization/probabilities.html"
    style="width:1000px; height: 500px; border: 0px;""></iframe>
       zThis visualization cannot be used if you have set `calculate_probabilities` to False as it uses the topic probabilities of all topics. r   zThere are no values where `min_probability` is higher than the probabilities that were supplied. Lower `min_probability` to prevent this error.N_         z...   z	<b>Topic z</b>: (   z#C8D2D7z#6E8484)colorr   )r   lineh)xymarkerorientationProbabilitygffffff?g      ?centertop   Black)sizer   )textr   r   xanchoryanchorfontsimple_whitewhite   Rockwell)bgcolor	font_sizefont_family)xaxis_titler   templater   r	   
hoverlabel)lenshape
ValueErrornpargwhereflattentolist
isinstancestrtopic_aspects_joincustom_labels_	_outliers	get_topicappendremovegoFigureBardictupdate_layout)topic_modelr   r   r   r   r   r	   
labels_idxvalstopiclabelsllabelidxwordswordfigs                    k/home/sietch6/trending-topics-pipeline/venv/lib/python3.12/site-packages/bertopic/plotting/_distribution.pyvisualize_distributionrO      s   P =1$A
 	
 =89:a?_
 	
 ]o=>FFHJ$++-D -%gqr^cCJ%&)C)CM)RSX)YYrrCIJa#((!BQ%8E!H89JJPVWu3u:?%cr
U0BBWW		#	#	/MU_`c+,,S;3H3H-HI`` 	0C))#.E-22AY7Ta77#C5sxx.?@.1%j2ocr
U*5e$M#./	0 ))
	3 	

C !gb0
  2:N    J] s8JW` 8s0   (I?II"	I2I&#I!-I&I)gQ?Fz%<b>Topic Probability Distribution</b>i   iX  )numpyr1   typingr   plotly.graph_objectsgraph_objectsr>   ndarrayfloatboolr6   intr?   rO        rN   <module>rZ      s      ! #&+8g::g g s#	g
 g g g YYgrY   