
    Q-j
                       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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rd dlmZ d dlmZ d dlmZ  ej2                         r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d      	 dddd	 	 	 	 	 	 	 	 	 dd       ZddZ 	 	 	 	 	 	 	 	 	 	 	 	 ddZ!	 	 	 	 	 	 d dZ"	 	 	 	 	 	 	 	 d!dZ#y)"    )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_namec               X    t        j                          t        t        | |||            S )a  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 or a :class:`numpy.ndarray` of
        :class:`matplotlib.axes.Axes` objects.
    )r   check_get_slice_plotr   )studyparamsr   r   s       t/Users/jameslopez/projects/TradingBot25/.venv/lib/python3.12/site-packages/optuna/visualization/matplotlib/_slice.py
plot_slicer   !   s&    B NN/vv{STT    c           	     n   t        | j                        dk(  rt        j                         \  }}|S t        j                  d      }d}t        j                  j                  d       t        | j                        dk(  rOt        j                         \  }}|j                  d       t        | j                  d   |||| j                        }nt        j                  d   d   dz  }t        j                  d   d   }	t        j                  dt        | j                        d	|t        | j                        z  |	f
      \  }}|j                  d       t        | j                        D ]#  \  }
}||
   }t        ||||| j                        }% |j                  |      }|j                  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)info_r&   cmappadding_ratiofigaxsscmin_figwidthfighightisubplotaxcbs                r   r   r   F   sv   
4==Q2	 << DMIIMM(
4==Q<<>Sl# %T]]1%5sD-QUQaQab "**+;<Q?!C&&'78;<<!C$66A	
S 	\" $DMM2JAwQB("dM4K[K[\B 3 <<s<#DNN7Jr   c                :   |j                  | j                  |       d }t        g g g       }t        g g g       }t        | j                  | j
                  | j                  | j                        D ]  \  }}	}
}| j                  r||rR|j                  j                  |       |j
                  j                  |	       |j                  j                  |
       k|j                  j                  |       |j
                  j                  |	       |j                  j                  |
        | j                  r|j                  d       d}| j                  r=|j                  }|j
                  }|j                  }|j                  }|j
                  }n"t        | |      \  }}}t        | |      \  }}}d}t        ||z   ||      }|j                  |d   |d          |j                  ||||d      }|j                  ||dd	
       |j!                          |S )N)xlabelylabellogcategoricalr   r"   grey)cr6   
edgecolorsz#cccccczInfeasible Trial)rF   label)set
param_namer	   zipxytrial_numbersconstraintsis_numericalappendis_log
set_xscale_get_categorical_plot_values_calc_lim_with_paddingset_xlimscatterlabel_outer)subplot_infor&   r6   r7   r   scalefeasible
infeasiblerL   rM   numrF   
feasible_x
feasible_y
feasible_cinfeasible_xinfeasible_yr5   xlimr:   s                       r   r.   r.   o   s    FF,))+F>E2r2&HRR(J(B(BLD\D\1c1 $$JJa JJa ""))#.LL"LL"$$++C0 
e  ZZ
ZZ
++
!||!||-I,X`-a*
J
(D\S](^%lA!*|";]ERDKKQa!	J
jtPV	WBJJ|\Y>PJQNNIr   c                   | j                   J g }g }g }t        t              }t        |j                  |j
                  |j                        D ]  \  }}}||   j                  ||f        | j                   D ]K  }	||	   D ]A  \  }}|j                  t        |	             |j                  |       |j                  |       C M |||fS N)	x_labelsr   listrK   rL   rM   rN   rQ   repr)
rY   valuesvalue_xvalue_yvalue_cpoints_dictrL   rM   numberx_labels
             r   rT   rT      s       ,,,GGGd#KFHHfhh0D0DE1fAq&k* F(($W-IAvNN4=)NN1NN6" . )
 GW$$r   c                   t        |       }t        |       }|dk(  rt        j                  |      t        j                  |      z
  |z  }t        j                  dt        j                  |      |z
        t        j                  dt        j                  |      |z         fS |dk(  r$t        t        |             dz
  }||z  }| ||z   fS ||z
  |z  }||z
  ||z   fS )NrC   
   rD   r"   )maxminmathlog10powr(   rI   )ri   r7   rZ   	value_max	value_minpaddingwidths          r   rU   rU      s     FIFI~::i(4::i+@@MQHHRI.89HHRI.89
 	
 
-	CK 1$-'x((y(M97"I$777r   re   )
r   r   r   zlist[str] | Noner   z%Callable[[FrozenTrial], float] | Noner   strreturn'Axes | np.ndarray')r4   r
   r|   r}   )rY   r   r&   z'Axes'r6   z
'Colormap'r7   floatr   r{   r|   z'PathCollection')rY   r   ri   r	   r|   z(tuple[list[Any], list[float], list[int]])ri   z	list[Any]r7   r~   rZ   z
str | Noner|   ztuple[float, float])$
__future__r   collectionsr   rt   typingr   r   numpynp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   r.   rT   rU    r   r   <module>r      s>   " #      2 < 3 6 9 H ("( 8HLNRG 7  $!U 59(!U!U!U 2	!U
 !U !U !UH&R/#// / 	/
 / /d%#%-8%-%$88&+84>88r   