Commit 0e6edd8b authored by Hafiz Emin Kosar's avatar Hafiz Emin Kosar
Browse files

added inline plots and moved files

parent 636ba7f6
%% Cell type:code id: tags:
``` python
%matplotlib notebook
from ipywidgets import interact, interactive, fixed, HBox, VBox
import ipywidgets as widgets
from IPython.display import clear_output, display, HTML
from IPython.display import Markdown as md
from src.laplace_plot import pzPoint, pzPlot
from ient_nb.ient_plots import *
from src.laplace.laplace_plot import pzPoint, pzPlot
from src.laplace.inline_plot import inline_plot
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np
```
%% Cell type:code id: tags:
``` python
pzp = pzPlot()
inline_plot('right')
```
%% Cell type:code id: tags:
filter_type = interactive(pzp.update_filter,filtr=widgets.Dropdown(options=list(pzp.filter_types.keys()), value="manuell", description='Filter'))
``` python
inline_plot('left')
```
%% Cell type:code id: tags:
``` python
%matplotlib notebook
%matplotlib notebook
pzp = pzPlot()
filter_type = interactive(pzp.update_filter,filtr=widgets.Dropdown(options=list(pzp.filter_types.keys()), value="Sprungfunktion", description='Filter'))
action_type = interactive(pzp.update_action,action=widgets.Dropdown(options=list(pzp.action_types.keys()),value="Hinzufügen", description='Modus'))
point_type = interactive(pzp.update_mode,mode=widgets.Dropdown(options=list(pzp.mode_types.keys()), value="Polstelle", description='Typ'))
amp_type = interactive(pzp.update_amp, H0=widgets.IntSlider(min=1,max=10,step=1,value=1), description="H0")
left_box = VBox([filter_type, amp_type])
right_box = VBox([action_type, point_type])
HBox([left_box, right_box])
```
%% Cell type:code id: tags:
``` python
# mehrfache Polstelle bei komplex funktioniert nicht
# H0 anzeigen
# Achse wandert hoch - ient_axis?
# Achsenlimits anpassen
# Achsenüberschriften P/N- Diagramm, Übertragungsfunktion, Impulsantwort
# update_signal todos beachten
# dirac spitzer!
# f statt omega
# Skript S. 18 2.2 P/N-Diagramm, 2 Cells versch. KBs, pn und t plotten
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
......
import matplotlib.pyplot as plt
from ient_nb.ient_plots import *
def inline_plot(roc='right'):
figr = plt.figure(figsize=(16, 4))
gs = gridspec.GridSpec(1, 2)
ax1 = plt.subplot(gs[0])
ient_axis(ax1)
ax2 = plt.subplot(gs[1])
ient_axis(ax2)
ax1.set_xlim(-2.5, 2.5)
ax1.set_ylim(-2.5, 2.5)
ax1.set_xlabel(r'$\rightarrow \mathrm{Re}$')
ax1.set_ylabel(r'$\uparrow \mathrm{Im}$')
_ = ax1.set_xticklabels([])
_ = ax1.set_yticklabels([])
ax2.set_xlim(-2.5, 2.5)
ax2.set_ylim(-2.5, 2.5)
ax2.set_xlabel(r'$\rightarrow \mathrm{t}$')
ax2.set_ylabel(r'$\uparrow \mathrm{s(t)}$')
_ = ax2.set_xticklabels([])
_ = ax2.set_yticklabels([])
y1 = [-12, -12]
y2 = [12, 12]
t = np.linspace(-3, 3, num=12000)
if roc == 'left':
xx = [-12, -1.5]
y = - np.exp(-1.5 * t) * np.where(t < 0, 1, 0)
else:
xx = [-1.5, 12]
y = np.exp(-1.5 * t) * np.where(t >= 0, 1, 0)
lline = ax1.plot([xx[0], xx[0]], [y1[0], y2[0]], ls="--", c="b")
rline = ax1.plot([xx[1], xx[1]], [y1[0], y2[0]], ls="--", c="b")
roc = ax1.fill_between(xx, y1, y2, facecolor="none", hatch="/", edgecolor="b", linewidth=0.0)
_ = ax1.text(-1.75, -2.75, '-Re{b}', fontsize=12)
_ = ax2.text(0.05, 1, '1', fontsize=12)
_ = ax2.text(0.05, -1, '-1', fontsize=12)
#_ = ax2.annotate('1', xy=(0, 1), xytext=(0.05, 1))
#_ = ax2.annotate('-1', xy=(0, -1), xytext=(0.05, -1))
ax2.plot(t, y)
\ No newline at end of file
import bisect
import src.funcs as func
import src.signal as sig
from src.plotting import plot
import timeit
import matplotlib.pyplot as plt
from ient_nb.ient_plots import *
......@@ -45,11 +48,17 @@ class pzPlot():
def __init__(self, pp=np.array([0]), pz=np.array([]), ord_p=np.array([1]), ord_z=np.array([])):
self.open_figure()
self.H0 = 1
self.filter = 'unit'
self.length = 1024
self.t = np.linspace(-6, 6, num=self.length)
self.f = np.linspace(-6, 6, num=self.length) # TODO - f statt omega
self.open_figure()
# Poles
self.pp = np.array([])
if pp.size != 0 and ord_p.size == 0:
......@@ -74,7 +83,7 @@ class pzPlot():
def open_figure(self):
fig = plt.figure(figsize=(9, 9))
fig = plt.figure(figsize=(13, 13))
gs = gridspec.GridSpec(2, 2)
# First axis for plotting s and h
......@@ -97,10 +106,16 @@ class pzPlot():
self.fig.canvas.mpl_connect('button_press_event', onclick)
self.handles['axh'] = plt.subplot(gs[1, 0])
self.handles['lineh'], = self.handles['axh'].plot(self.t, self.t)
ient_axis(self.handles['axh'])
self.handles['axH'] = plt.subplot(gs[1, 1])
self.handles['lineH'], = self.handles['axH'].plot(self.f, self.f)
ient_axis(self.handles['axH'])
# TODO ient_axis für H ändern
#self.handles['axH'].spines['bottom'].set_position('center')
# matplotlib spines
plt.subplots_adjust(wspace=.25)
......@@ -345,6 +360,8 @@ class pzPlot():
def update_plot(self):
# TODO - Laufzeit beachten, y data ändern falls kein dirac vorhanden
poles = np.array(list((x.p for x in self.pp)), dtype=complex)
poles_order = np.array(list((x.order for x in self.pp)))
zeroes = np.array(list((x.p for x in self.pz)), dtype=complex)
......@@ -352,26 +369,43 @@ class pzPlot():
# TODO - butterworth? -> verändere H0 nicht
H0 = self.H0
length = 1024
t = np.linspace(-6, 6, num=length)
omega = np.linspace(-6, 6, num=length)
#t = np.linspace(-6, 6, num=self.length)
#omega = np.linspace(-6, 6, num=length)
roc = self.roc['sigma']
s_t, S_f = func.calc_laplace(t, omega, H0, poles, zeroes, poles_order, zeroes_order, roc)
s_t, S_f = func.calc_laplace(self.t, self.f, H0, poles, zeroes, poles_order, zeroes_order, roc)
# TODO - ylims anpassen
self.handles['axh'].clear()
#self.handles['axh'].clear()
ient_axis(self.handles['axh'])
self.handles['axh'].set_xlim(-6, 6)
self.handles['axh'].set_ylim(-6, 6)
self.handles['axh'].set_xlabel(r'$\rightarrow \mathrm{t}$')
self.handles['axh'].set_ylabel(r'$\uparrow \mathrm{s(t)}$')
sig.Signal().plot(t, s_t, self.handles['axh'])
#self.handles['axh'].set_xlim(-6, 6)
#self.handles['axh'].set_ylim(-6, 6)
#self.handles['axh'].set_xlabel(r'$\rightarrow \mathrm{t}$')
#self.handles['axh'].set_ylabel(r'$\uparrow \mathrm{s(t)}$')
self.handles['axH'].clear()
ient_axis(self.handles['axH'])
self.handles['axH'].set_xlim(-6, 6)
start = timeit.default_timer()
# Your statements here
#sig.Signal().plot(self.t, s_t, self.handles['axh'])
#self.handles['lineh'].set_ydata(s_t)
plot(self.t, s_t, self.handles['axh'])
# TODO - dirac handeln
#self.handles['axH'].clear()
#ient_axis(self.handles['axH'])
#self.handles['axH'].set_xlim(-6, 6)
#self.handles['axH'].set_ylim(np.amin(S_f) - 1, np.amax(S_f) + 1)
self.handles['axH'].set_xlabel(r'$\rightarrow \mathrm{w}$')
self.handles['axH'].set_ylabel(r'$\uparrow \mathrm{|S(jw)| [dB]}$')
sig.Signal().plot(omega, S_f, self.handles['axH'])
#self.handles['axH'].set_xlabel(r'$\rightarrow \mathrm{w}$')
#self.handles['axH'].set_ylabel(r'$\uparrow \mathrm{|S(jw)| [dB]}$')
#sig.Signal().plot(self.f, S_f, self.handles['axH'])
plot(self.f, S_f, self.handles['axH'])
stop = timeit.default_timer()
print('Time: ', stop - start)
#self.handles['lineH'].set_ydata(S_f)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment