Skip to content

Commit 8ab765f

Browse files
authored
Merge pull request #47 from Axiomatic-AI/fix-plot-bug
Fix plot bug
2 parents bb32e74 + c19cb9d commit 8ab765f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/axiomatic/pic_helpers.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,23 @@ def plot_parameter_history(parameters: List[Parameter], parameter_history: List[
209209
are dictionaries where keys correspond to the
210210
second part of the parameter path.
211211
Returns:
212-
None: This function displays the plots and does not return any value.
212+
fig: The figure object containing the plots.
213213
"""
214214
plt.clf()
215-
215+
216+
# Create figure and axes
216217
fig, axs = plt.subplots(len(parameters), 1, figsize=(10, 5 * len(parameters)), sharex=True)
217218
fig.suptitle("Parameter History vs. Iterations")
218219
fig.supxlabel("Iterations")
219220
fig.supylabel("Parameter Values")
220-
221+
222+
# Handle the case where there's only one parameter (axs becomes a single Axes object instead of a list)
223+
if len(parameters) == 1:
224+
axs = [axs]
225+
221226
for i, param in enumerate(parameters):
222-
split_param = param.path.split(",")
223227
if "," in param.path:
228+
split_param = param.path.split(",")
224229
axs[i].plot(
225230
[parameter_history[j][split_param[0]][split_param[1]] for j in range(len(parameter_history))],
226231
label=param.path
@@ -232,7 +237,7 @@ def plot_parameter_history(parameters: List[Parameter], parameter_history: List[
232237
)
233238
axs[i].legend()
234239
axs[i].grid(True)
235-
240+
236241
plt.tight_layout(rect=[0, 0, 1, 0.96])
237242
plt.close(fig)
238243
return fig

0 commit comments

Comments
 (0)