Thanks to Aras Database and E. Bertrand for sharing his NovaPer2020 dataset for this example.
#install if needed
!pip install specutils
!pip install astropy
!pip install plotly
import plotly.graph_objects as go
from astropy import units as u #units
from astropy.io import fits
import astropy.wcs as fitswcs #wcs
from specutils import Spectrum1D
#list spectrums (all in data folder here)
spec_list = ['spec3d_data/1.fit',
'spec3d_data/2.fit',
'spec3d_data/3.fit',
'spec3d_data/4.fit',
'spec3d_data/5.fit',
'spec3d_data/6.fit',
'spec3d_data/7.fit',
'spec3d_data/8.fit',
'spec3d_data/9.fit',
'spec3d_data/10.fit',
'spec3d_data/11.fit',
'spec3d_data/12.fit',
'spec3d_data/13.fit',
'spec3d_data/14.fit',
'spec3d_data/15.fit',
'spec3d_data/16.fit',
'spec3d_data/17.fit']
#init x,y,z arrays
x_array = []
z_array = []
y_array = []
#parse spec list and create a spec for each item
for item in spec_list:
#y_pos = listspec.index(item)
file = fits.open(item)
specdata = file[0].data
header = file[0].header
#make WCS object
wcs_data = fitswcs.WCS(header={'CDELT1': header['CDELT1'], 'CRVAL1': header['CRVAL1'],
'CUNIT1': header['CUNIT1'], 'CTYPE1': header['CTYPE1'],
'CRPIX1': header['CRPIX1']})
#set flux units
flux= specdata * u.Jy
#create a Spectrum1D object with specutils
spec = Spectrum1D(flux=flux, wcs=wcs_data)
#add values to x,y,z array
x_array.append(spec.spectral_axis.value)
z_array.append(spec.flux.value)
y_array.append(header['DATE-OBS'])
#create figure
#color list here : https://plotly.com/python/builtin-colorscales/
fig = go.Figure(data=[go.Surface(z=z_array, y=y_array, x=x_array, colorscale='Viridis')])
#set legend, size,...
fig.update_layout(title='Ha Evolution NovaPer2020 - EBE - Lhires III', autosize=True,
width=800, height=800,
scene = {
"xaxis": {"nticks": 10, "title" : "Wavelength (Å)"},
"yaxis": {"nticks": 10, "title" : "Date"},
"zaxis": {"nticks": 5, "title" : "Flux"},
'camera_eye': {"x": 0, "y": -1, "z": 0.5},
"aspectratio": {"x": 1, "y": 1, "z":0.3}
}
)
#show contour on top
#fig.update_traces(contours_z=dict(show=True, usecolormap=True,
# highlightcolor="limegreen", project_z=True))
#show plot
fig.show()