Skip to content

Commit

Permalink
Refactor save_fig function to add support for tight layout in general…
Browse files Browse the repository at this point in the history
…_utils.py (#27)
  • Loading branch information
d31003 authored Apr 25, 2024
1 parent dadd2fc commit ae942ea
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions swarm_visualizer/utility/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ def set_plot_properties(
sns.set_style(style="darkgrid")


def save_fig(fig, save_loc: str = None, dpi: int = 600) -> None:
def save_fig(fig, save_loc: str = None, dpi: int = 600, tight_layout: bool=True) -> None:
"""Save figure.
:param fig: figure
:param save_loc: location to save the figure
:param dpi: dpi
:param tight_layout: tight layout or not
:return: None.
"""
plt.tight_layout() if tight_layout else None
# If save location doesn't exist, create it
if not os.path.exists(os.path.dirname(save_loc)):
os.makedirs(os.path.dirname(save_loc))
os.makedirs(os.path.dirname(save_loc), exist_ok=True)

# Save the figure
fig.savefig(save_loc, dpi=dpi)
Expand Down

0 comments on commit ae942ea

Please sign in to comment.