diff --git a/src/rimsschemedrawer/plotter.py b/src/rimsschemedrawer/plotter.py index 8f96b2f..840efcc 100644 --- a/src/rimsschemedrawer/plotter.py +++ b/src/rimsschemedrawer/plotter.py @@ -56,22 +56,16 @@ def __init__(self, data: dict, **kwargs): self._figure, self._axes = kwargs.get("fig_ax", plt.subplots(1, 1)) - # Colors for arrows + # Colors for headspace and main if darkmode: self.colmain = "#ffffff" - self.colir = "#d27878" - self.coluv = "#8c96df" - self.colfuv = "#9365b2" - self.colpump = "#60a55b" self.colhdr = "#4b5482" # header color else: self.colmain = "#000000" - self.colir = "#a00000" - self.coluv = "#0012a0" - self.colfuv = "#5f00a0" - self.colpump = "#0aa000" self.colhdr = "#adbbff" # header color + self.darkmode = darkmode + # now plot the scheme self._plotit() @@ -221,14 +215,7 @@ def _plotit(self): # draw the arrows for the steps for it in range(len(lambda_steps)): - if lambda_steps[it] >= 700: - col = self.colir - elif 500.0 < lambda_steps[it] < 700.0: - col = self.colpump - elif 350.0 < lambda_steps[it] <= 500.0: - col = self.coluv - else: - col = self.colfuv + col = ut.color_wavelength(lambda_steps[it], self.darkmode) # xvalue for arrow xval += deltax wstp = wavenumber_steps[it] @@ -362,15 +349,7 @@ def _plotit(self): ) for it in range(len(wavenumber_es)): - if lambda_step_es[it] >= 700: - col = self.colir - elif 500.0 < lambda_step_es[it] < 700.0: - col = self.colpump - elif 350.0 < lambda_step_es[it] <= 500.0: - col = self.coluv - else: - col = self.colfuv - + col = ut.color_wavelength(lambda_step_es[it], self.darkmode) # values for spacing and distance xval = firstarrowxmfl + x_spacing_es + it * x_spacing_es yval = mfld_yinc * ipvalue * (1 + it) diff --git a/src/rimsschemedrawer/utils.py b/src/rimsschemedrawer/utils.py index dcabdf4..144ff40 100644 --- a/src/rimsschemedrawer/utils.py +++ b/src/rimsschemedrawer/utils.py @@ -149,6 +149,61 @@ PLOT_STYLES = ["light", "dark", "light transparent", "dark transparent"] +def color_wavelength(lmb: float, darkmode: bool = False) -> str: + """Color the wavelength according to the wavelength. + + When darkmode is turned on, pastel colors are used. Definitions of colors are + taken from here: + https://sciencenotes.org/visible-light-spectrum-wavelengths-and-colors/ + + :param lmb: Wavelength in nm. + + :return: Color string. + """ + dict_light = { + "ir": "#500000", + "red": "#b70000", + "orange": "#d75700", + "yellow": "#c09e00", + "green": "#0aa000", + "light_blue": "#0098ff", + "deep_blue": "#0012a0", + "violet": "#5f00a0", + } + dict_dark = { + "ir": "#b98989", + "red": "#d27878", + "orange": "#ffa669", + "yellow": "#f4e67c", + "green": "#60a55b", + "light_blue": "#82b1d1", + "deep_blue": "#8c96df", + "violet": "#9e85af", + } + + if darkmode: + dict_use = dict_dark + else: + dict_use = dict_light + + if lmb > 700: # infrared + return dict_use["ir"] + elif lmb >= 625: # red + return dict_use["red"] + elif lmb >= 590: # orange + return dict_use["orange"] + elif lmb >= 565: # yellow + return dict_use["yellow"] + elif lmb >= 500: # green + return dict_use["green"] + elif lmb >= 484: # light blue + return dict_use["light_blue"] + elif lmb >= 450: # deep blue + return dict_use["deep_blue"] + else: # violet + return dict_use["violet"] + + def cm_2_to_nm(cm: Union[float, np.ndarray]) -> Union[float, np.ndarray]: """Convert a wavenumber in cm^-1 to a wavelength in nm.