diff --git a/src/maths/diagrams/__init__.py b/src/maths/diagrams/__init__.py index 6b4eff7..a6b09d0 100644 --- a/src/maths/diagrams/__init__.py +++ b/src/maths/diagrams/__init__.py @@ -6,6 +6,7 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from src.maths.diagrams.sets import *; +from src.maths.diagrams.signal import *; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # EXPORTS @@ -14,4 +15,5 @@ from src.maths.diagrams.sets import *; __all__ = [ 'Function', 'Functions', + 'display_signal', ]; diff --git a/src/maths/diagrams/signal.py b/src/maths/diagrams/signal.py new file mode 100644 index 0000000..2187df5 --- /dev/null +++ b/src/maths/diagrams/signal.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from __future__ import annotations; + +from src.thirdparty.code import *; +from src.thirdparty.types import *; +from src.thirdparty.maths import *; +from src.thirdparty.plots import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +__all__ = [ + 'display_signal', +]; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# CONSTANTS / VARIABLES +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +def display_signal( + u: np.ndarray, + title: str, + max_labels = 10, +): + n = len(u); + if n <= max_labels: + x_axis = list(range(n)); + else: + skip = int(n/max_labels); + x_axis = [ k*skip for k in range(max_labels) ]; + + fig, axs = mplot.subplots(1, 1, constrained_layout=True); + mplot.title(title); + mplot.xlabel('»Zeit« [=Indizes]'); + mplot.ylabel('Werte [=Einträge]'); + axs.stem(linspace(0,n-1,n), np.real(u), label='reeller Teil', linefmt='red'); + axs.stem(linspace(0,n-1,n) + 0.05, np.imag(u), label='imaginärer Teil', linefmt='lime'); + mplot.legend(); + axs.set_xticks(x_axis, labels=[ str(index) for index in x_axis]); + mplot.show(); + return; diff --git a/src/thirdparty/maths.py b/src/thirdparty/maths.py index 39f3820..debcaff 100644 --- a/src/thirdparty/maths.py +++ b/src/thirdparty/maths.py @@ -6,10 +6,17 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from fractions import Fraction; +from numpy import cos; +from numpy import exp; +from numpy import linalg; +from numpy import linspace; +from numpy import pi; +from numpy import sin; +from numpy import sqrt; +from typing import TypeVar; import math; import numpy as np; import random; -from typing import TypeVar; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # MODIFICATIONS @@ -39,8 +46,15 @@ def sample( __all__ = [ 'Fraction', + 'cos', + 'exp', + 'linalg', + 'linspace', 'math', 'np', + 'pi', 'random', 'sample', + 'sin', + 'sqrt', ]; diff --git a/src/thirdparty/render.py b/src/thirdparty/render.py index 33b4893..477c6dc 100644 --- a/src/thirdparty/render.py +++ b/src/thirdparty/render.py @@ -19,11 +19,11 @@ from qiskit.visualization import array_to_latex; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __all__ = [ + 'Latex', 'array_to_latex', + 'display', 'display_latex', 'display_markdown', 'display_png', - 'display', - 'Latex', 'widgets', ]; diff --git a/src/thirdparty/types.py b/src/thirdparty/types.py index 17ec4d3..b9bfd2f 100644 --- a/src/thirdparty/types.py +++ b/src/thirdparty/types.py @@ -38,8 +38,8 @@ from typing import Generic; from typing import Optional; from typing import Type; from typing import TypeVar; -from typing_extensions import Concatenate; -from typing_extensions import ParamSpec; +from typing import Concatenate; +from typing import ParamSpec; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # EXPORTS