Skip to content

Commit

Permalink
Merge pull request #40 from adtzlr/fix-plots
Browse files Browse the repository at this point in the history
Fix plots: Change default config, fix overlap of texts and replace `fps` by `duration`
  • Loading branch information
adtzlr committed May 3, 2023
2 parents df3027f + dd1adea commit 5b1668b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. The format

## [Unreleased]

### Changed
- Change default config from `Model.plot_model(config="both")` to `Model.plot_model(config="deformed")`.
- Change default config from `Model.plot_movie(config="both")` to `Model.plot_movie(config="deformed")`.

### Fixed
- Fix overlapping title and text in `Model.plot_model()` and `Model.plot_movie()`: Change relative position of the force-scale text box in `tools.plot_utilities.p_model()` from `ax.text2D(0.3, 1.05, verticalalignment="top")` to `ax.text2D(0.5, 0.95, verticalalignment="top", horizontalalignment="center")`. Now identical arguments for calling 2D (`ax.text()`) and 3D (`ax.text2D()`) are used.
- Don't pass `fps` to `imagio.mimwrite()` (use the default settings instead).

### Removed
- Remove pre-defined

## [1.0.3] - 2023-03-15

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/trusspy/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.3"
__version__ = "1.0.4"
6 changes: 4 additions & 2 deletions src/trusspy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def plt_extforces(self, config="undeformed"):

def plot_model(
self,
config="both",
config=["deformed"],
view="xz",
contour=None,
lim_scale=1.2,
Expand All @@ -700,14 +700,15 @@ def plot_model(

def plot_movie(
self,
config="both",
config=["deformed"],
view="xz",
contour=None,
lim_scale=1.2,
force_scale=0.5,
nodesize=10,
cbar_limits="auto",
incs="all",
**kwargs,
):
p_movie(
self,
Expand All @@ -719,6 +720,7 @@ def plot_movie(
nodesize,
cbar_limits,
incs,
**kwargs,
)

def plot_history(
Expand Down
6 changes: 4 additions & 2 deletions src/trusspy/tools/movie_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import imageio


def png_to_gif(workdir=r"figures/", png_subdir=r"png/", gif_subdir=r"gif/"):
def png_to_gif(workdir=r"figures/", png_subdir=r"png/", gif_subdir=r"gif/", **kwargs):
png_dir = workdir + png_subdir
gif_dir = workdir + gif_subdir
images = []
Expand All @@ -24,4 +24,6 @@ def png_to_gif(workdir=r"figures/", png_subdir=r"png/", gif_subdir=r"gif/"):
if file_name.endswith(".png"):
file_path = os.path.join(png_dir, file_name)
images.append(imageio.imread(file_path))
imageio.mimwrite(gif_dir + r"movie.gif", images, fps=5, subrectangles=True)
imageio.mimwrite(
gif_dir + r"movie.gif", images, subrectangles=True, **kwargs
)
11 changes: 7 additions & 4 deletions src/trusspy/tools/plot_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,24 @@ def p_model(
props = dict(boxstyle="round", facecolor="C2", alpha=0.25)
if view == "3d":
ax.text2D(
0.3,
1.05,
0.5,
0.95,
textstr,
transform=ax.transAxes,
fontsize=11,
verticalalignment="top",
horizontalalignment="center",
bbox=props,
)
else:
ax.text(
0.05,
0.5,
0.95,
textstr,
transform=ax.transAxes,
fontsize=11,
verticalalignment="top",
horizontalalignment="center",
bbox=props,
)

Expand Down Expand Up @@ -216,6 +218,7 @@ def p_movie(
nodesize=10,
cbar_limits="auto",
incs="all",
**kwargs,
):
if incs == "all":
if self.Settings.nsteps > 1:
Expand All @@ -242,7 +245,7 @@ def p_movie(
plt.savefig("figures/png/fig_{:03d}.png".format(i), dpi=200)
plt.close("all")

png_to_gif()
png_to_gif(**kwargs)


def p_path(self, nodepath, increment=-1, Y="Displacement X", fig=None, ax=None):
Expand Down

0 comments on commit 5b1668b

Please sign in to comment.