Fix contour plot of matplotlib#5892
Conversation
|
This pull request has not seen any recent activity. |
|
@nabenabe0928 Could you review this PR? |
HideakiImamura
left a comment
There was a problem hiding this comment.
Thanks for the PR. The change looks good to me. Is it possible to introduce the test cases to validate this change?
|
The PR description could be better by the following revisions: Describe how they look differentlyIn my eyes, the difference was not that obvious. Claim which figure is for matplotlibIn the first figure, it is not obvious which figure shows the result obtained by matplotlib, so it would be much more friendly with the guide. Add a code block for smoother PR reviewsIt is not that hard to add a code block, but it significantly makes reviews easier. Demo Codeimport optuna
import matplotlib.pyplot as plt
def objective(trial: optuna.Trial) -> float:
category = trial.suggest_categorical("category", ["foo", "bar"])
if category == "foo":
return (trial.suggest_float("x1", 0, 10) - 2) ** 2
else:
return -((trial.suggest_float("x2", -10, 0) + 5) ** 2)
study = optuna.create_study()
study.optimize(objective, n_trials=50)
fig = optuna.visualization.plot_contour(study)
fig.show()
optuna.visualization.matplotlib.plot_contour(study)
plt.show() |
|
Note Seems the interpolation algorithm is a bit different from plotly, but that is not a range of this PR, so I will leave it as is. |
|
I fixed comments. |
|
@fusawa-yugo Could you add a unittest for this change? |
|
@HideakiImamura |
HideakiImamura
left a comment
There was a problem hiding this comment.
Thanks for the discussion. I agree with you. It would be great to work on the test of matplotlib contour tests as a follow-up.
Motivation
Outputs of coutour plot are different between plotly and matplotlib.
Visualization of matplotlib is not working properly.
Use these and visualize through
optuna.visualization.matplotlib.plot_contourhttps://github.com/optuna/optuna-visualization-regression-tests/blob/6b98f408f82a613fc5271cfb12308649e3d55211/studies.py#L45-L53
https://github.com/optuna/optuna-visualization-regression-tests/blob/6b98f408f82a613fc5271cfb12308649e3d55211/studies.py#L24-L29
In this case, if
categoryisbar,x1is missing as shown below.Now, when plotting a gragh related to
x1,baris dropped fromcategoryaxis.This is the same for
fooandx1.Description of the changes
I solved this by including all values on the axis with a categorical distribution, regardless of whether the value on the other axis is None.