Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion optuna/visualization/matplotlib/_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ def _get_timeline_plot(info: _TimelineInfo) -> "Axes":
# There are 5 types of TrialState in total.
# However, the legend depicts only types present in the arguments.
legend_handles = []
present_state_names = set(_get_state_name(b) for b in info.bars)
for state_name, color in _cm.items():
if any(_get_state_name(b) == state_name for b in info.bars):
if state_name in present_state_names:
legend_handles.append(matplotlib.patches.Patch(color=color, label=state_name))
ax.legend(handles=legend_handles, loc="upper left", bbox_to_anchor=(1.05, 1.0))
fig.tight_layout()
Expand Down