From d8d7a93229cea1c7004cfd67fa06e64ef20cca4b Mon Sep 17 00:00:00 2001 From: Agent6-6-6 <36808164+Agent6-6-6@users.noreply.github.com> Date: Sun, 31 Jul 2022 22:34:40 +1200 Subject: [PATCH 1/2] Fix legend formatting --- sectionproperties/post/post.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/sectionproperties/post/post.py b/sectionproperties/post/post.py index 49b01886..65d20b64 100644 --- a/sectionproperties/post/post.py +++ b/sectionproperties/post/post.py @@ -7,9 +7,7 @@ @contextlib.contextmanager -def plotting_context( - ax=None, pause=True, title="", filename="", render=True, axis_index=None, **kwargs -): +def plotting_context(ax=None, pause=True, title="", filename="", render=True, axis_index=None, **kwargs): """Executes code required to set up a matplotlib figure. :param ax: Axes object on which to plot @@ -49,9 +47,7 @@ def plotting_context( except (AttributeError, TypeError): pass # only 1 axis, not an array except IndexError as exc: - raise ValueError( - f"axis_index={axis_index} is not compatible with arguments to subplots: {kwargs}" - ) from exc + raise ValueError(f"axis_index={axis_index} is not compatible with arguments to subplots: {kwargs}") from exc else: fig = ax.get_figure() ax_supplied = True @@ -60,6 +56,9 @@ def plotting_context( yield fig, ax + # if no axes was supplied, finish the plot and return the figure and axes + plt.tight_layout() + ax.set_aspect("equal", anchor="C") ax.set_title(title) @@ -67,9 +66,6 @@ def plotting_context( # if an axis was supplied, don't continue with displaying or configuring the plot return - # if no axes was supplied, finish the plot and return the figure and axes - plt.tight_layout() - if filename: fig.savefig(filename, dpi=fig.dpi) plt.close(fig) # close the figure to free the memory From 5a336abe18074b8a217c82c08e318322229b27d6 Mon Sep 17 00:00:00 2001 From: Agent6-6-6 <36808164+Agent6-6-6@users.noreply.github.com> Date: Mon, 1 Aug 2022 19:19:03 +1200 Subject: [PATCH 2/2] Fix title cutting off, move comment back --- sectionproperties/post/post.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sectionproperties/post/post.py b/sectionproperties/post/post.py index 65d20b64..b2c7ba49 100644 --- a/sectionproperties/post/post.py +++ b/sectionproperties/post/post.py @@ -7,7 +7,9 @@ @contextlib.contextmanager -def plotting_context(ax=None, pause=True, title="", filename="", render=True, axis_index=None, **kwargs): +def plotting_context( + ax=None, pause=True, title="", filename="", render=True, axis_index=None, **kwargs +): """Executes code required to set up a matplotlib figure. :param ax: Axes object on which to plot @@ -47,7 +49,9 @@ def plotting_context(ax=None, pause=True, title="", filename="", render=True, ax except (AttributeError, TypeError): pass # only 1 axis, not an array except IndexError as exc: - raise ValueError(f"axis_index={axis_index} is not compatible with arguments to subplots: {kwargs}") from exc + raise ValueError( + f"axis_index={axis_index} is not compatible with arguments to subplots: {kwargs}" + ) from exc else: fig = ax.get_figure() ax_supplied = True @@ -56,12 +60,11 @@ def plotting_context(ax=None, pause=True, title="", filename="", render=True, ax yield fig, ax - # if no axes was supplied, finish the plot and return the figure and axes + ax.set_title(title) plt.tight_layout() - ax.set_aspect("equal", anchor="C") - ax.set_title(title) + # if no axes was supplied, finish the plot and return the figure and axes if ax_supplied: # if an axis was supplied, don't continue with displaying or configuring the plot return