Update workflow configuration and replace Altair with Matplotlib for signal visualizations
This commit is contained in:
parent
6cc2200683
commit
0503034e40
6 changed files with 115 additions and 61 deletions
|
@ -32,32 +32,26 @@ et un niveau **bas** ("Low").
|
|||
:label: logique
|
||||
```{code-cell} python
|
||||
:tags: [remove-input]
|
||||
import altair as alt
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import ticker
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
rng = np.random.default_rng(25)
|
||||
|
||||
n = 16
|
||||
t = np.arange(n+1)
|
||||
s = rng.choice([0, 1], n+1)
|
||||
s[-1] = s[-2]
|
||||
data = pd.DataFrame({
|
||||
"t": t,
|
||||
"s": s,
|
||||
})
|
||||
alt.Chart(
|
||||
data
|
||||
).mark_line(
|
||||
interpolate="step-after",
|
||||
strokeWidth=3,
|
||||
).encode(
|
||||
alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,n)),
|
||||
alt.Y("s:Q", axis=alt.Axis(title="Signal logique", values=[0, 1], format=".0f")).scale(domain=(0,1)),
|
||||
).properties(
|
||||
width="container",
|
||||
height=100,
|
||||
s = rng.choice([0, 1], n)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.stairs(s, t, lw=3)
|
||||
ax.set(
|
||||
xlim=(0, n),
|
||||
ylim=(-.5, 1.5),
|
||||
xlabel="Temps (s)",
|
||||
ylabel="Signal logique",
|
||||
)
|
||||
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
|
||||
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
|
||||
```
|
||||
Exemple de signal logique
|
||||
````
|
||||
|
@ -77,35 +71,38 @@ Un exemple de signal analogique est donné en @analogique.
|
|||
:label: analogique
|
||||
```{code-cell} python
|
||||
:tags: [remove-input]
|
||||
import altair as alt
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import ticker
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from scipy.interpolate import CubicSpline
|
||||
from scipy.stats import qmc
|
||||
|
||||
|
||||
rng = np.random.default_rng(25)
|
||||
|
||||
n = 20
|
||||
t_max = 16
|
||||
|
||||
t = np.linspace(0, t_max, n)
|
||||
|
||||
t_base = np.linspace(0, t_max, n)
|
||||
lhs = (qmc.LatinHypercube(d=n-2, rng=rng).random(1)[0] - .5) * t_max/n
|
||||
t = t_base + np.concatenate(([0], lhs, [0]))
|
||||
t = t_base
|
||||
s = 5 * rng.random(n)
|
||||
s[-1] = s[-2]
|
||||
data = pd.DataFrame({
|
||||
"t": t,
|
||||
"s": s,
|
||||
})
|
||||
alt.Chart(
|
||||
data
|
||||
).mark_line(
|
||||
interpolate="basis",
|
||||
strokeWidth=3,
|
||||
).encode(
|
||||
alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,t_max)),
|
||||
alt.Y("s:Q", axis=alt.Axis(title="Signal analogique")).scale(domain=(0,5)),
|
||||
).properties(
|
||||
width="container",
|
||||
height=200,
|
||||
|
||||
t_interp = np.linspace(0, t_max, 1024)
|
||||
s_interp = np.clip(CubicSpline(t, s)(t_interp), 0, 5)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.plot(t_interp, s_interp, lw=3)
|
||||
ax.set(
|
||||
xlim=(0, t_max),
|
||||
ylim=(-.5, 5.5),
|
||||
xlabel="Temps (s)",
|
||||
ylabel="Signal analogique",
|
||||
)
|
||||
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
|
||||
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
|
||||
```
|
||||
Exemple de signal analogique
|
||||
````
|
||||
|
@ -119,32 +116,38 @@ Un exemple de signal analogique est donné en @numerique.
|
|||
:label: numerique
|
||||
```{code-cell} python
|
||||
:tags: [remove-input]
|
||||
import altair as alt
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import ticker
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
rng = np.random.default_rng(25)
|
||||
|
||||
n = 16
|
||||
t = np.arange(n+1)
|
||||
s = rng.integers(0, 16, n+1)
|
||||
s[-1] = s[-2]
|
||||
data = pd.DataFrame({
|
||||
"t": t,
|
||||
"s": s,
|
||||
})
|
||||
alt.Chart(
|
||||
data
|
||||
).mark_line(
|
||||
interpolate="step-after",
|
||||
strokeWidth=3,
|
||||
).encode(
|
||||
alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,n)),
|
||||
alt.Y("s:Q", axis=alt.Axis(title="Signal numérique", values=np.arange(0, 16))).scale(domain=(0,15)),
|
||||
).properties(
|
||||
width="container",
|
||||
height=200,
|
||||
s = rng.integers(0, 16, n)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.stairs(s, t, lw=3)
|
||||
ax.set(
|
||||
xlim=(0, n),
|
||||
ylim=(-.5, 16.5),
|
||||
xlabel="Temps (s)",
|
||||
ylabel="Signal numérique",
|
||||
)
|
||||
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
|
||||
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
|
||||
# alt.Chart(
|
||||
# data
|
||||
# ).mark_line(
|
||||
# interpolate="step-after",
|
||||
# strokeWidth=3,
|
||||
# ).encode(
|
||||
# alt.X("t:Q").axis(title="Temps (s)").scale(domain=(0,n)),
|
||||
# alt.Y("s:Q", axis=alt.Axis(title="Signal numérique", values=np.arange(0, 16))).# scale(domain=(0,15)),
|
||||
# ).properties(
|
||||
# width="container",
|
||||
# height=200,
|
||||
# )
|
||||
```
|
||||
Exemple de signal numérique
|
||||
````
|
Loading…
Add table
Add a link
Reference in a new issue