4444from spotpython .utils .numpy2json import NumpyEncoder
4545
4646# Setting up the backend to use QtAgg
47- matplotlib .use ("TkAgg" )
47+ # matplotlib.use("TkAgg")
48+ # matplotlib.use("Agg")
4849
4950
5051logger = logging .getLogger (__name__ )
@@ -259,6 +260,9 @@ def __init__(
259260 self .n_points = self .fun_control ["n_points" ]
260261 self .max_surrogate_points = self .fun_control ["max_surrogate_points" ]
261262 self .progress_file = self .fun_control ["progress_file" ]
263+ self .tkagg = self .fun_control ["tkagg" ]
264+ if self .tkagg :
265+ matplotlib .use ("TkAgg" )
262266
263267 # Tensorboard:
264268 self .init_spot_writer ()
@@ -1447,7 +1451,7 @@ def infill(self, x) -> float:
14471451 return self .surrogate .predict (X )
14481452
14491453 def plot_progress (
1450- self , show = True , log_x = False , log_y = False , filename = "plot.png" , style = ["ko" , "k" , "ro-" ], dpi = 300
1454+ self , show = True , log_x = False , log_y = False , filename = "plot.png" , style = ["ko" , "k" , "ro-" ], dpi = 300 , tkagg = False
14511455 ) -> None :
14521456 """Plot the progress of the hyperparameter tuning (optimization).
14531457
@@ -1495,6 +1499,8 @@ def plot_progress(
14951499 S.plot_progress(log_y=True)
14961500
14971501 """
1502+ if tkagg :
1503+ matplotlib .use ("TkAgg" )
14981504 fig = pylab .figure (figsize = (9 , 6 ))
14991505 s_y = pd .Series (self .y )
15001506 s_c = s_y .cummin ()
@@ -1904,6 +1910,7 @@ def plot_contour(
19041910 figsize = (12 , 6 ),
19051911 use_min = False ,
19061912 use_max = True ,
1913+ tkagg = False ,
19071914 ) -> None :
19081915 """Plot the contour of any dimension."""
19091916
@@ -1942,6 +1949,8 @@ def plot_contour_subplots(X, Y, Z, ax, min_z, max_z, contour_levels):
19421949 contour = ax .contourf (X , Y , Z , contour_levels , zorder = 1 , cmap = "jet" , vmin = min_z , vmax = max_z )
19431950 pylab .colorbar (contour , ax = ax )
19441951
1952+ if tkagg :
1953+ matplotlib .use ("TkAgg" )
19451954 fig = setup_plot ()
19461955
19471956 (X , Y ), x , y = generate_mesh_grid (self .lower , self .upper , n_grid )
@@ -2017,6 +2026,7 @@ def plot_important_hyperparameter_contour(
20172026 dpi = 200 ,
20182027 use_min = False ,
20192028 use_max = True ,
2029+ tkagg = False ,
20202030 ) -> None :
20212031 """
20222032 Plot the contour of important hyperparameters.
@@ -2123,6 +2133,7 @@ def plot_important_hyperparameter_contour(
21232133 dpi = dpi ,
21242134 use_max = use_max ,
21252135 use_min = use_min ,
2136+ tkagg = tkagg ,
21262137 )
21272138
21282139 def get_importance (self ) -> list :
@@ -2181,7 +2192,7 @@ def print_importance(self, threshold=0.1, print_screen=True) -> list:
21812192 print ("Importance requires more than one theta values (n_theta>1)." )
21822193 return output
21832194
2184- def plot_importance (self , threshold = 0.1 , filename = None , dpi = 300 , show = True ) -> None :
2195+ def plot_importance (self , threshold = 0.1 , filename = None , dpi = 300 , show = True , tkagg = False ) -> None :
21852196 """Plot the importance of each variable.
21862197
21872198 Args:
@@ -2198,6 +2209,8 @@ def plot_importance(self, threshold=0.1, filename=None, dpi=300, show=True) -> N
21982209 None
21992210 """
22002211 if self .surrogate .n_theta > 1 :
2212+ if tkagg :
2213+ matplotlib .use ("TkAgg" )
22012214 theta = np .power (10 , self .surrogate .theta )
22022215 imp = 100 * theta / np .max (theta )
22032216 idx = np .where (imp > threshold )[0 ]
0 commit comments