Skip to content

Commit

Permalink
Merge pull request optuna#5892 from fusawa-yugo/fusawa-yugo/check-vis…
Browse files Browse the repository at this point in the history
…ualization

Fix contour plot of matplotlib
  • Loading branch information
HideakiImamura authored Jan 20, 2025
2 parents 0fff6ed + eceb0d1 commit 59bf669
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion optuna/visualization/matplotlib/_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ def _calculate_axis_data(
returned_values: Sequence[int | float]
if axis.is_cat:
enc = _LabelEncoder()
returned_values = enc.fit_transform(list(map(str, values)))
# Fit LabelEncoder with all the categories in categorical distribution.
enc.fit(list(map(str, filter(lambda value: value is not None, axis.values))))
# Then transform the values using the fitted label encoder.
# Note that `values` may not include all the categories,
# so we use `axis.values` for fitting.
returned_values = enc.transform(list(map(str, values)))
cat_param_labels = enc.get_labels()
cat_param_pos = enc.get_indices()
else:
Expand Down

0 comments on commit 59bf669

Please sign in to comment.