o
    }oi                     @  s6  d dl mZ d dlmZ d dl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 d d	l
mZ d d
l
mZ d dlmZ erTd dlmZ d dlmZ d dlmZ e rvd 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	d	d<dddd=d!d"Zd>d%d&Zd?d/d0Zd@d4d5Z dAd:d;Z!dS )B    )annotations)defaultdictN)Any)TYPE_CHECKING)experimental_func)_get_slice_plot_info)_PlotValues)_SlicePlotInfo)_SliceSubplotInfo)_imports)Callable)Study)FrozenTrial)Axes)Colormap)
matplotlib)PathCollection)pltz2.2.0zObjective Value)targettarget_namestudyr   paramslist[str] | Noner   %Callable[[FrozenTrial], float] | Noner   strreturn'Axes'c                C  s   t   tt| |||S )aV  Plot the parameter relationship as slice plot in a study with Matplotlib.

    .. seealso::
        Please refer to :func:`optuna.visualization.plot_slice` for an example.

    Args:
        study:
            A :class:`~optuna.study.Study` object whose trials are plotted for their target values.
        params:
            Parameter list to visualize. The default is all parameters.
        target:
            A function to specify the value to display. If it is :obj:`None` and ``study`` is being
            used for single-objective optimization, the objective values are plotted.

            .. note::
                Specify this argument if ``study`` is being used for multi-objective optimization.
        target_name:
            Target's name to display on the axis label.


    Returns:
        A :class:`matplotlib.axes.Axes` object.
    )r   check_get_slice_plotr   )r   r   r   r    r   Z/home/ubuntu/.local/lib/python3.10/site-packages/optuna/visualization/matplotlib/_slice.py
plot_slice   s    r!   infor	   c                 C  s  t | jdkrt \}}|S td}d}tjd t | jdkr;t \}}|d t| jd |||| j}nAt	j
d d d }t	j
d d }	tjdt | jd	|t | j |	fd
\}}|d t| jD ]\}
}||
 }t||||| j}qj|j||d}|d |S )Nr   Bluesg?ggplot   z
Slice Plotzfigure.figsize   T)shareyfigsize)axTrial)lensubplotsr   get_cmapstyleuse	set_title_generate_slice_subplotr   r   rcParamssuptitle	enumeratecolorbar	set_label)r"   _r)   cmappadding_ratiofigaxsscmin_figwidthfighightisubplotaxcbr   r   r    r   C   s2   




r   subplot_infor
   r)   r8   
'Colormap'r9   float'PathCollection'c                 C  sr  |j | j|d d }tg g g }tg g g }t| j| j| j| jD ]=\}}	}
}|d us7|dks7|	d us7|	dkr^|rL|j| |j|	 |j|
 q!|j| |j|	 |j|
 q!| j	ri|
d d}| jr||j}|j}|j}|j}|j}nt| |\}}}t| |\}}}d}t|| ||}||d |d  |j||||dd}|j||d	d
d |  |S )N)xlabelylabelNonelogcategoricalr   r%   grey)cr8   
edgecolorsz#cccccczInfeasible Trial)rL   label)set
param_namer   zipxytrial_numbersconstraintsappendis_log
set_xscaleis_numerical_get_categorical_plot_values_calc_lim_with_paddingset_xlimscatterlabel_outer)rB   r)   r8   r9   r   scalefeasible
infeasiblerR   rS   numrL   
feasible_x
feasible_y
feasible_cinfeasible_xinfeasible_yr7   xlimr<   r   r   r    r1   l   sD    
r1   valuesr   (tuple[list[Any], list[float], list[int]]c           
      C  s   | j d usJ g }g }g }tt}t|j|j|jD ]\}}}|| ||f q| j D ]}	||	 D ]\}}|t|	 || || q2q,|||fS N)	x_labelsr   listrQ   rR   rS   rT   rV   r   )
rB   ri   value_xvalue_yvalue_cpoints_dictrR   rS   numberx_labelr   r   r    rZ      s   


rZ   	list[Any]r_   
str | Nonetuple[float, float]c                 C  s   t | }t| }|dkr.t|t| | }tdt|| tdt|| fS |dkrEtt| d }|| }| || fS || | }|| || fS )NrI   
   rJ   r%   )maxminmathlog10powr+   rO   )ri   r9   r_   	value_max	value_minpaddingwidthr   r   r    r[      s   r[   rk   )
r   r   r   r   r   r   r   r   r   r   )r"   r	   r   r   )rB   r
   r)   r   r8   rC   r9   rD   r   r   r   rE   )rB   r
   ri   r   r   rj   )ri   rt   r9   rD   r_   ru   r   rv   )"
__future__r   collectionsr   rz   typingr   r   optuna._experimentalr   optuna.visualization._slicer   r   r	   r
   3optuna.visualization.matplotlib._matplotlib_importsr   collections.abcr   optuna.studyr   optuna.trialr   is_successfulr   r   r   r   r   r!   r   r1   rZ   r[   r   r   r   r    <module>   s>    
#
)
.