Skip to content

Commit 8c311ce

Browse files
committed
add optional file_name_suffix param to show_history_chart
1 parent e026bf9 commit 8c311ce

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

ptmlib/charts.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def format_plt(fig_size: (int, int) = (10, 6)) -> None:
1212

1313

1414
def show_history_chart(history: Any, search_string: str, fig_size: (int, int) = (10, 6),
15-
save_fig_enabled: bool = False) -> None:
15+
save_fig_enabled: bool = False, file_name_suffix: str = None) -> None:
1616

1717
"""
1818
Renders line charts for TensorFlow training history (ex: accuracy, loss),
@@ -22,6 +22,7 @@ def show_history_chart(history: Any, search_string: str, fig_size: (int, int) =
2222
:param search_string: string to filter history; ex: accuracy, loss
2323
:param fig_size: chart size tuple; default is (10, 6)
2424
:param save_fig_enabled: save chart image with search_string-YYYYmmdd-HHMMSS.png file format
25+
:param file_name_suffix: suffix for file name; default is a timestamp
2526
:return: None
2627
"""
2728

@@ -33,6 +34,12 @@ def show_history_chart(history: Any, search_string: str, fig_size: (int, int) =
3334
plt.minorticks_on()
3435

3536
if save_fig_enabled:
36-
plt.savefig(f"{search_string}-{get_time_string()}.png")
37+
if file_name_suffix is None:
38+
image_file_name = f'{search_string}-{get_time_string()}.png'
39+
else:
40+
image_file_name = f'{search_string}-{file_name_suffix}.png'
41+
42+
plt.savefig(image_file_name)
43+
print('Saved image:', image_file_name)
3744

3845
plt.show()

0 commit comments

Comments
 (0)