Skip to content

Commit bf137ce

Browse files
Don't unnecessarily save figures!
1 parent f0cc421 commit bf137ce

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

magritte/plot.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def image_mpl(
5858
npix_y = 300,
5959
x_unit = units.au,
6060
v_unit = units.km/units.s,
61-
method = 'nearest'
61+
method = 'nearest',
62+
save_fig = False
6263
):
6364
"""
6465
Create plots of the channel maps of a synthetic observation (image) with matplotlib.
@@ -81,6 +82,8 @@ def image_mpl(
8182
Unit of length for the vertical (y) axis.
8283
method : str
8384
Method to interpolate the scattered intensity data onto a regular image grid.
85+
save_fig : bool
86+
Whether to save the output figure.
8487
8588
Returns
8689
-------
@@ -220,7 +223,8 @@ def image_mpl(
220223
ax0.set_xlabel('Optical depth [.]', labelpad=11)
221224
ax2.set_ylabel('Relative optical depth', labelpad=15)
222225

223-
plt.savefig(f"{im_dir}/image_{f:0>3d}.png", bbox_inches='tight')
226+
if save_fig:
227+
plt.savefig(f"{im_dir}/image_{f:0>3d}.png", bbox_inches='tight')
224228

225229
figs.append(fig)
226230

@@ -242,7 +246,8 @@ def image_plotly(
242246
v_unit = units.km/units.s,
243247
method = 'nearest',
244248
width = 620, # Yields approx square channel map
245-
height = 540 # Yields approx square channel map
249+
height = 540, # Yields approx square channel map
250+
save_fig = False
246251
):
247252
"""
248253
Create plots of the channel maps of a synthetic observation (image) with plotly.
@@ -269,6 +274,8 @@ def image_plotly(
269274
Width of the resulting figure.
270275
height : float
271276
Height of the resulting figure.
277+
save_fig : bool
278+
Whether to save the output figure.
272279
273280
Returns
274281
-------
@@ -549,8 +556,9 @@ def image_plotly(
549556
"scrollZoom": True
550557
}
551558

552-
# Save figure as html file
553-
fig.write_html(f"{im_dir}/image.html", config=config)
559+
if save_fig:
560+
# Save figure as html file
561+
fig.write_html(f"{im_dir}/image.html", config=config)
554562

555563
return fig.show(config=config)
556564

0 commit comments

Comments
 (0)