77import numpy as np
88import itertools
99
10+ from autoarray .util import array_util
1011from autoarray .plotters import plotter_util
1112
1213
@@ -125,7 +126,7 @@ def plot_grid(
125126 plotter_util .plot_lines (line_lists = lines )
126127
127128 plt .tick_params (labelsize = xyticksize )
128- plotter_util . output_figure (
129+ output_figure (
129130 array = None ,
130131 as_subplot = as_subplot ,
131132 output_path = output_path ,
@@ -250,3 +251,37 @@ def plot_points(grid, points, pointcolor):
250251 s = 8 ,
251252 color = pointcolor ,
252253 )
254+
255+
256+ def output_figure (array , as_subplot , output_path , output_filename , output_format ):
257+ """Output the figure, either as an image on the screen or to the hard-disk as a .png or .fits file.
258+
259+ Parameters
260+ -----------
261+ array : ndarray
262+ The 2D array of image to be output, required for outputting the image as a fits file.
263+ as_subplot : bool
264+ Whether the figure is part of subplot, in which case the figure is not output so that the entire subplot can \
265+ be output instead using the *output_subplot_array* function.
266+ output_path : str
267+ The path on the hard-disk where the figure is output.
268+ output_filename : str
269+ The filename of the figure that is output.
270+ output_format : str
271+ The format the figue is output:
272+ 'show' - display on computer screen.
273+ 'png' - output to hard-disk as a png.
274+ 'fits' - output to hard-disk as a fits file.'
275+ """
276+ if not as_subplot :
277+
278+ if output_format is "show" :
279+ plt .show ()
280+ elif output_format is "png" :
281+ plt .savefig (output_path + output_filename + ".png" , bbox_inches = "tight" )
282+ elif output_format is "fits" :
283+ array_util .numpy_array_1d_to_fits (
284+ array_1d = array ,
285+ file_path = output_path + output_filename + ".fits" ,
286+ overwrite = True ,
287+ )
0 commit comments