Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
wiheto committed Apr 4, 2022
1 parent 816a3ad commit f8dafd4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ plt.show()

### Plotting a rotating GIF


```python
netplotbrain.plot(template='MNI152NLin2009cAsym',
templatestyle='surface',
Expand Down
2 changes: 1 addition & 1 deletion netplotbrain/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def plot(nodes=None, fig: Optional[plt.Figure]=None, ax=None, view: str='L', fra
ax_out.append(ax)

# Add legends to plot
if legends is not None and profile['gif'] == False:
if legends is not None and profile['gif'] is False:
for li, legend in enumerate(legends):
# setup legend subplot. Goes in centre or centre2 subplots
spind = gridspec.ncols
Expand Down
18 changes: 9 additions & 9 deletions netplotbrain/plotting/plot_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ def _plot_gif(fig, ax, gifduration, savename=None, gif_loop=0):
ax : list of subplot axes
fig : matplotlib figure
gifduration: each frame in ms, int (600 is suggested)
gif_loop: number of loops, int
If 0, it becomes an infinite loop
savename: str (default 'netplotbrain.gif')
Name of the saved GIF
"""

#Ensure that savename ends in gif
if savename is None:
if savename is None:
raise ValueError('savename must be specified to save gif')
# Add give to end of the
if savename.endswith('.gif') == False:
# Add give to end of the
if savename.endswith('.gif') is False:
savename += '.gif'

#saving matplotlib figures (frame images) to buffer and opening in PIL Image objects
images = []

for i, current_ax in enumerate(ax):
extent = current_ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
buf = io.BytesIO()
fig.savefig(buf, bbox_inches=extent, format='PNG', dpi=300)
buf.seek(i)
img = Image.open(buf).convert('RGBA')
images.append(img)

images[0].save(savename,
save_all=True, append_images=images[1:], optimize=False, duration=gifduration, loop=gif_loop)
save_all=True, append_images=images[1:], optimize=False, duration=gifduration, loop=gif_loop)

0 comments on commit f8dafd4

Please sign in to comment.