mpl
This commit is contained in:
parent
31eeb53dea
commit
9e77fc8f03
8 changed files with 57 additions and 40 deletions
|
@ -10,11 +10,11 @@ plt.rcParams.update({
|
|||
'legend.fontsize': 23,
|
||||
})
|
||||
|
||||
|
||||
from .utils import setup_matplotlib
|
||||
|
||||
def plot_spectrum(wavelengths, intensities, title=''):
|
||||
|
||||
plt.figure(figsize=(10, 6), dpi=300)
|
||||
setup_matplotlib()
|
||||
plt.figure()
|
||||
plt.plot(wavelengths, intensities, 'o-', markersize=2)
|
||||
plt.xlabel(r'$\lambda$ (nm)')
|
||||
plt.ylabel(r'$I^*$')
|
||||
|
@ -46,11 +46,14 @@ def finds_peak(wavelengths, intensities, min_peak_prominence, min_peak_distance=
|
|||
(peaks_min, peaks_max)
|
||||
|
||||
"""
|
||||
if plot:
|
||||
setup_matplotlib()
|
||||
|
||||
peaks_max, _ = find_peaks(intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||
peaks_min, _ = find_peaks(-intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||
|
||||
if plot:
|
||||
plt.figure(figsize=(10, 6), dpi=300)
|
||||
plt.figure()
|
||||
plt.plot(wavelengths, intensities, 'o-', markersize=2, label="Smoothed data")
|
||||
plt.plot(wavelengths[peaks_max], intensities[peaks_max], 'ro')
|
||||
plt.plot(wavelengths[peaks_min], intensities[peaks_min], 'ro')
|
||||
|
|
|
@ -4,16 +4,8 @@ from scipy.fftpack import fft, ifft, fftfreq
|
|||
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
plt.rc('text', usetex=True)
|
||||
plt.rcParams.update({
|
||||
'axes.labelsize': 26,
|
||||
'xtick.labelsize': 32,
|
||||
'ytick.labelsize': 32,
|
||||
'legend.fontsize': 23,
|
||||
})
|
||||
|
||||
|
||||
from .utils import OptimizeResult
|
||||
from .utils import OptimizeResult, setup_matplotlib
|
||||
|
||||
|
||||
|
||||
|
@ -43,6 +35,9 @@ def thickness_from_fft(wavelengths, intensities,
|
|||
results : Instance of `OptimizeResult` class.
|
||||
The attribute `thickness` gives the thickness value in nm.
|
||||
"""
|
||||
if plot:
|
||||
setup_matplotlib()
|
||||
|
||||
if num_half_space is None:
|
||||
num_half_space = 10 * len(wavelengths)
|
||||
|
||||
|
@ -74,7 +69,7 @@ def thickness_from_fft(wavelengths, intensities,
|
|||
thickness_fft = freq_max / 2.
|
||||
|
||||
if plot:
|
||||
plt.figure(figsize=(10, 6), dpi=300)
|
||||
plt.figure()
|
||||
plt.loglog(inverse_wavelengths_fft, np.abs(intensities_fft))
|
||||
plt.loglog(freq_max, np.abs(intensities_fft[idx_max_fft]), 'o')
|
||||
plt.xlabel('Frequency')
|
||||
|
@ -91,7 +86,7 @@ def thickness_from_fft(wavelengths, intensities,
|
|||
#
|
||||
# # # # 1. Spectre original
|
||||
# # if plot:
|
||||
# # plt.figure(figsize=(10, 6), dpi=150)
|
||||
# # plt.figure()
|
||||
# # plt.plot(1/wavelengths, intensities, label='Spectre original')
|
||||
# # plt.xlabel('1/Longueur d\'onde (nm-1)')
|
||||
# # plt.ylabel('Intensité')
|
||||
|
@ -119,7 +114,7 @@ def thickness_from_fft(wavelengths, intensities,
|
|||
# F_max = freqs_pos[idx_max]
|
||||
#
|
||||
# if plot:
|
||||
# plt.figure(figsize=(10, 6), dpi=150)
|
||||
# plt.figure()
|
||||
# plt.plot(freqs_pos, abs_fft_pos, label='|FFT|')
|
||||
# plt.axvline(F_max, color='r', linestyle='--', label='Pic principal')
|
||||
# plt.xlabel('Distance optique [nm]')
|
||||
|
@ -153,7 +148,7 @@ def thickness_from_fft(wavelengths, intensities,
|
|||
#
|
||||
# # 9. Affichage reconstruction
|
||||
# if plot:
|
||||
# plt.figure(figsize=(10, 6), dpi=150)
|
||||
# plt.figure()
|
||||
# plt.plot(lambda_reconstructed, intensities_k, '--', label='Original interpolé')
|
||||
# plt.plot(lambda_reconstructed, signal_filtered_HF,'--', color='gray')
|
||||
#
|
||||
|
|
|
@ -5,15 +5,8 @@ from skimage.measure import ransac, LineModelND
|
|||
from scipy.signal import find_peaks
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
plt.rc('text', usetex=True)
|
||||
plt.rcParams.update({
|
||||
'axes.labelsize': 26,
|
||||
'xtick.labelsize': 32,
|
||||
'ytick.labelsize': 32,
|
||||
'legend.fontsize': 23,
|
||||
})
|
||||
|
||||
from .utils import OptimizeResult
|
||||
from .utils import OptimizeResult, setup_matplotlib
|
||||
|
||||
|
||||
def thickness_from_minmax(wavelengths,
|
||||
|
@ -56,6 +49,8 @@ def thickness_from_minmax(wavelengths,
|
|||
see the documentation of `scipy.signal.find_peaks`. This function
|
||||
is used to find extrema.
|
||||
"""
|
||||
if plot:
|
||||
setup_matplotlib()
|
||||
|
||||
peaks_max, _ = find_peaks(intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||
peaks_min, _ = find_peaks(-intensities, prominence=min_peak_prominence, distance=min_peak_distance)
|
||||
|
@ -106,7 +101,7 @@ def thickness_from_minmax(wavelengths,
|
|||
#slope = slransac.estimator_.coef_[0]
|
||||
|
||||
if plot:
|
||||
fig, ax = plt.subplots(figsize=(10, 6), dpi=600)
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
ax.set_xlabel('extremum n°')
|
||||
ax.set_ylabel('$n$($\lambda$) / $\lambda$')
|
||||
|
@ -133,7 +128,7 @@ def thickness_from_minmax(wavelengths,
|
|||
thickness_minmax = 1 / slope / 4
|
||||
|
||||
if plot:
|
||||
fig, ax = plt.subplots(figsize=(8, 6))
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
ax.set_xlabel('extremum n°')
|
||||
ax.set_ylabel('1 / $\lambda$')
|
||||
|
|
|
@ -2,16 +2,9 @@ import numpy as np
|
|||
from scipy.optimize import curve_fit
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
plt.rc('text', usetex=True)
|
||||
plt.rcParams.update({
|
||||
'axes.labelsize': 26,
|
||||
'xtick.labelsize': 32,
|
||||
'ytick.labelsize': 32,
|
||||
'legend.fontsize': 23,
|
||||
})
|
||||
|
||||
from .io import load_spectrum
|
||||
from .utils import OptimizeResult
|
||||
from .utils import OptimizeResult, setup_matplotlib
|
||||
from .analysis import finds_peak
|
||||
|
||||
|
||||
|
@ -160,6 +153,9 @@ def thickness_from_scheludko(wavelengths,
|
|||
DESCRIPTION.
|
||||
|
||||
"""
|
||||
if plot:
|
||||
setup_matplotlib()
|
||||
|
||||
max_tested_order = 12
|
||||
r_index = refractive_index
|
||||
|
||||
|
@ -196,7 +192,7 @@ def thickness_from_scheludko(wavelengths,
|
|||
best_h_values = None
|
||||
|
||||
if plot:
|
||||
plt.figure(figsize=(10, 6), dpi=300)
|
||||
plt.figure()
|
||||
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
||||
plt.xlabel(r'$\lambda$ ($ \mathrm{nm} $)')
|
||||
|
||||
|
@ -242,7 +238,7 @@ def thickness_from_scheludko(wavelengths,
|
|||
if plot:
|
||||
Delta_values = Delta(wavelengths_masked, fitted_h, best_m, r_index_masked)
|
||||
|
||||
plt.figure(figsize=(10, 6), dpi=300)
|
||||
plt.figure()
|
||||
plt.plot(wavelengths_masked, DeltaVrai,
|
||||
'bo-', markersize=2, label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
||||
|
||||
|
@ -268,6 +264,8 @@ def thickness_for_order0(wavelengths,
|
|||
refractive_index,
|
||||
min_peak_prominence,
|
||||
plot=None):
|
||||
if plot:
|
||||
setup_matplotlib()
|
||||
|
||||
# TODO :
|
||||
# Load "trou"
|
||||
|
@ -303,7 +301,7 @@ def thickness_for_order0(wavelengths,
|
|||
Imin=intensities_I_min_masked)
|
||||
|
||||
if plot:
|
||||
plt.figure(figsize=(10, 6), dpi=300)
|
||||
plt.figure()
|
||||
plt.plot(wavelengths_masked, best_h_values, label=r"Épaisseur du film (Scheludko, m=0)")
|
||||
plt.ylabel(r'$h$ ($\mathrm{{nm}}$)')
|
||||
plt.xlabel(r'$\lambda$ (nm)')
|
||||
|
@ -326,7 +324,7 @@ def thickness_for_order0(wavelengths,
|
|||
if plot:
|
||||
Delta_values = Delta(wavelengths_masked, fitted_h, best_m, r_index_masked)
|
||||
|
||||
plt.figure(figsize=(10, 6), dpi=300)
|
||||
plt.figure()
|
||||
plt.plot(wavelengths_masked, DeltaVrai,
|
||||
'bo-', markersize=2, label=r'$\mathrm{{Smoothed}}\ \mathrm{{Data}}$')
|
||||
|
||||
|
|
|
@ -25,3 +25,26 @@ class OptimizeResult(dict):
|
|||
|
||||
def __dir__(self):
|
||||
return list(self.keys())
|
||||
|
||||
|
||||
|
||||
|
||||
def is_latex_installed():
|
||||
import shutil
|
||||
return shutil.which("latex") is not None or shutil.which("pdflatex") is not None
|
||||
|
||||
def setup_matplotlib():
|
||||
"""
|
||||
Configure matplotlib with LaTeX text rendering and custom font sizes.
|
||||
|
||||
"""
|
||||
import matplotlib.pyplot as plt
|
||||
plt.rc('text', usetex=is_latex_installed())
|
||||
plt.rcParams.update({
|
||||
'figure.dpi': 300,
|
||||
'figure.figsize': (10, 6),
|
||||
'axes.labelsize': 26,
|
||||
'xtick.labelsize': 32,
|
||||
'ytick.labelsize': 32,
|
||||
'legend.fontsize': 23,
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue