I've written a Python library that uses Matplotlib and Astropy to generate spectra from data of solar radio emissions. I'm satisfied with how it's plotting data from a single FITS file, but now I'm trying to plot data from multiple FITS files in a single figure adjacently. I've read some of Matplotlib's documentation and some questions related to this like How do I get multiple subplots in matplotlib?.
Here's part of the code that plots data from a single FITS file:
def plot_freq_range_db_above_background(self, start_freq, end_freq):
plt.figure(1, figsize=(11, 6))
plt.imshow(self.hdul_dataset['db'] - self.hdul_dataset['db_median'],
cmap='magma', norm=plt.Normalize(self.hdul_dataset['v_min'],
self.hdul_dataset['v_max']
),
aspect='auto', extent=[self.hdul_dataset['time_axis'][0],
self.hdul_dataset['time_axis']
[-1000],
self.hdul_dataset['frequency'][-1],
self.hdul_dataset['frequency'][0]])
plt.ylim(start_freq, end)
plt.gca().invert_yaxis()
plt.colorbar(label='dB above background')
plt.xlabel('Time (UT)', fontsize=15)
plt.ylabel('Frequency (MHz)', fontsize=15)
plt.title(self.filename, fontsize=16)
plt.tick_params(labelsize=14)
plt.show()
And this is an example of a plot generated by the method above:
So, what I'm trying to do now is to plot data from different files, and have all of them adjacent to each other in a single figure. The X-axis(frequency) is the same for every single plot, and the Y-axis(time) is continuous from one file to the next one.
Here's the method I've written trying to accomplish what I just described:
def plot_fits_files_list(files_list, start_freq, end_freq):
dim = len(files_list)
plt_index = 1
plt.figure(1)
for file in files_list:
fits_filename = file.split(os.sep)[-1]
fitsfile = ECallistoFitsFile(fits_filename)
fitsfile.set_file_path()
fitsfile.set_hdul_dataset()
plt.subplot(dim, dim, plt_index)
plt_index += 1
plt.imshow(
fitsfile.hdul_dataset['db'] -
fitsfile.hdul_dataset['db_median'],
cmap='magma',
norm=plt.Normalize(fitsfile.hdul_dataset['v_min'],
fitsfile.hdul_dataset['v_max']),
aspect='auto', extent=[fitsfile.hdul_dataset['time_axis'][0],
fitsfile.hdul_dataset['time_axis']
[-1000],
fitsfile.hdul_dataset['frequency'][-1],
fitsfile.hdul_dataset['frequency'][0]])
plt.ylim(start_freq, end_freq)
plt.gca().invert_yaxis()
plt.colorbar(label='dB above background')
plt.xlabel('Time (UT)', fontsize=15)
plt.ylabel('Frequency (MHz)', fontsize=15)
plt.title("Multiple Plots Test", fontsize=16)
plt.tick_params(labelsize=14)
plt.show()