Skip to content

Commit 59bf669

Browse files
Merge pull request optuna#5892 from fusawa-yugo/fusawa-yugo/check-visualization
Fix contour plot of matplotlib
2 parents 0fff6ed + eceb0d1 commit 59bf669

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

optuna/visualization/matplotlib/_contour.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ def _calculate_axis_data(
175175
returned_values: Sequence[int | float]
176176
if axis.is_cat:
177177
enc = _LabelEncoder()
178-
returned_values = enc.fit_transform(list(map(str, values)))
178+
# Fit LabelEncoder with all the categories in categorical distribution.
179+
enc.fit(list(map(str, filter(lambda value: value is not None, axis.values))))
180+
# Then transform the values using the fitted label encoder.
181+
# Note that `values` may not include all the categories,
182+
# so we use `axis.values` for fitting.
183+
returned_values = enc.transform(list(map(str, values)))
179184
cat_param_labels = enc.get_labels()
180185
cat_param_pos = enc.get_indices()
181186
else:

0 commit comments

Comments
 (0)