Mise en cohérence des styles de graphes

This commit is contained in:
Mattéo Delabre 2020-12-19 23:50:49 +01:00
parent e8a5336aca
commit 708b3ef4d7
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
6 changed files with 30 additions and 32 deletions

View File

@ -32,34 +32,30 @@ freq = freq[left:right]
values = values[left:right]
# Génération du graphe
plt.style.use('ggplot')
plt.rcParams.update({
'figure.figsize': (10, 5),
'font.size': 16,
'font.size': 18,
'font.family': 'Concourse T4',
})
fig, ax = plt.subplots()
ax.tick_params(axis='both', which='major', labelsize=12)
ax.plot(freq, values)
ax.grid(alpha=.3)
# Configuration des axes
def freq_format(value, pos):
return f'{value * freq_scale:.0f} Hz'
def ampl_format(value, pos):
return f'{value:.1f}'
ax.set_xlabel('Fréquence', labelpad=10)
ax.set_xscale('log', base=2)
ax.xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(freq_format))
ax.xaxis.set_major_locator(plt.MultipleLocator(100 / freq_scale))
ax.xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, pos: f'{x * freq_scale:.0f} Hz'))
ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(100 / freq_scale))
ax.xaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())
ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(10 / freq_scale))
ax.set_ylabel('Amplitude relative', labelpad=10)
ax.yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(ampl_format))
ax.yaxis.set_major_locator(plt.MultipleLocator(.2))
ax.yaxis.set_major_formatter(matplotlib.ticker.StrMethodFormatter('{x:.1f}'))
ax.yaxis.set_major_locator(matplotlib.ticker.MultipleLocator(.2))
ax.yaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())
ax.yaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(.05))
# Rendu du résultat
if output_file == '-':

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -17,45 +17,47 @@ output_file = sys.argv[2]
# Calcul du STFT
signal = soundbox.load_signal(source_file)
freq, time, vecs = sig.stft(signal, soundbox.samp_rate, nperseg=soundbox.samp_rate * 0.5)
values = np.absolute(vecs)
# Calcul de la fenêtre des fréquences intéressantes
high_enough = np.where(values.max(axis=1) / np.max(values) >= 0.01)
left = high_enough[0][0]
right = high_enough[0][-1]
freq = freq[left:right]
values = values[left:right]
# Génération du graphe
plt.rcParams.update({
'figure.figsize': (10, 8),
'figure.frameon': True,
'font.size': 20,
'font.size': 18,
'font.family': 'Concourse T4',
})
fig, ax = plt.subplots(frameon=True)
fig, ax = plt.subplots()
ax.tick_params(axis='both', which='major', labelsize=12)
freq_filter = values.max(axis=1) / np.max(values) >= 0.01
x = np.arange(len(values))
ax.pcolormesh(
time, freq[freq_filter], values[freq_filter],
cmap='Greys',
shading='gouraud')
ax.pcolormesh(time, freq, values, cmap='Greys', shading='gouraud')
ax.grid(alpha=.3)
# Configuration des axes
def time_format(value, pos):
return f'{value:.0f} s'
def freq_format(value, pos):
return f'{value:.0f} Hz'
ax.set_xlabel('Temps', labelpad=10)
ax.xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(time_format))
ax.xaxis.set_major_formatter(matplotlib.ticker.StrMethodFormatter('{x:.0f} s'))
ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(1))
ax.xaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())
ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(.2))
ax.set_ylabel('Fréquence', labelpad=10)
ax.set_yscale('log', base=2)
ax.yaxis.set_major_locator(plt.MultipleLocator(100))
ax.yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(freq_format))
ax.grid(alpha=.3)
ax.yaxis.set_major_formatter(matplotlib.ticker.StrMethodFormatter('{x:.0f} Hz'))
ax.yaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())
ax.yaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(10))
# Rendu du résultat
if output_file == '-':