To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 03c1eb18 authored by Cyrill Mast's avatar Cyrill Mast
Browse files

added semilog plot

added complex-plane plot
parent 33150107
......@@ -11,8 +11,8 @@ class PlotGeneral:
np.linspace(0, self.resolution - 1, self.resolution),
"The data in the x direction")
self._y_data = PassiveVariable(
np.zeros(self.resolution),
"The data in the x direction")
np.ones(self.resolution),
"The data in the y direction")
self._x_label = PassiveVariable(
"", "The label in the x-direction")
......@@ -21,8 +21,13 @@ class PlotGeneral:
self._title = PassiveVariable(
"", "The title")
self._fig, self._ax = plt.subplots()
self._ax.plot(self.x_data, self.y_data)
self._fig_semilogy, self._ax_semilogy = plt.subplots()
self._ax_semilogy.semilogy(self.x_data, self.y_data)
self._fig_complex, self._ax_complex = plt.subplots()
self._ax_complex.plot(self.x_data, self.y_data, marker="o")
plt.style.use('ggplot')
"""
......@@ -35,8 +40,12 @@ class PlotGeneral:
@x_data.setter
def x_data(self, value):
self._ax.lines[0].set_xdata(value)
self._ax.set_xlim(min(value), max(value))
self._ax_semilogy.lines[0].set_xdata(value)
self._ax_semilogy.set_xlim(
max(1e-80, min(value)), min(max(value), 1e5))
self._ax_complex.lines[0].set_xdata(value)
self._ax_complex.set_xlim(
max(1e-80, min(value)), min(max(value), 1e5))
self._x_data.value = value
@property
......@@ -45,8 +54,12 @@ class PlotGeneral:
@y_data.setter
def y_data(self, value):
self._ax.lines[0].set_ydata(value)
self._ax.set_ylim(min(value), max(value))
self._ax_semilogy.lines[0].set_xdata(value)
self._ax_semilogy.set_xlim(
max(1e-80, min(value)), min(max(value), 1e5))
self._ax_complex.lines[0].set_xdata(value)
self._ax_complex.set_xlim(
max(1e-80, min(value)), min(max(value), 1e5))
self._y_data.value = value
@property
......@@ -55,7 +68,8 @@ class PlotGeneral:
@x_label.setter
def x_label(self, value):
self._ax.set_xlabel(value)
self._ax_semilogy.set_xlabel(value)
self._ax_complex.set_xlabel(value)
self._x_label.value = value
@property
......@@ -64,7 +78,8 @@ class PlotGeneral:
@y_label.setter
def y_label(self, value):
self._ax.set_ylabel(value)
self._ax_semilogy.set_ylabel(value)
self._ax_complex.set_ylabel(value)
self._y_label.value = value
@property
......@@ -73,7 +88,8 @@ class PlotGeneral:
@title.setter
def title(self, value):
self._ax.set_title(value)
self._ax_semilogy.set_title(value)
self._ax_complex.set_title(value)
self._title.value = value
def rescale(self, resolution=None):
......@@ -88,7 +104,7 @@ class PlotGeneral:
d_out = d_in
return d_out
def figshow(self, figure):
def figshow(self, figure) -> None:
for i in plt.get_fignums():
if figure != plt.figure(i):
plt.close(plt.figure(i))
......
......@@ -10,67 +10,110 @@ class PlotVarious(PlotGeneral):
self.b = baseclass
self.res = 10
def plot_A_n(self, res=None) -> None:
def plot_A_n(self, real=True, twoD_plot=True, res=None) -> None:
"""
plots the first n coefficients of A_n
"""
if res is not None:
self.rescale(res)
self.x_data = np.linspace(0, self.res - 1, self.res)
self.y_data = [self.b.A_n(n) for n in self.x_data]
self.x_label = "n"
self.y_label = "A_n"
self.title = "The first {} coefficients of A_n".format(self.res)
self.figshow(self._fig)
_ = np.linspace(0, self.res - 1, self.res)
if twoD_plot:
self.x_data = [self.b.A_n(int(n)).real for n in _]
self.x_label = "real part of A_n"
self.y_data = [self.b.A_n(int(n)).imag for n in _]
self.y_label = "imaginary part of A_n"
self.figshow(self._fig_complex)
else:
self.x_data = _
self.x_label = "n"
if real:
self.y_data = [self.b.A_n(int(n)).real for n in _]
self.y_label = "real part of A_n"
else:
self.y_data = [self.b.A_n(int(n)).imag for n in _]
self.y_label = "imaginary part of A_n"
self.figshow(self._fig_semilogy)
def plot_B_n(self, res=None) -> None:
def plot_B_n(self, real=True, twoD_plot=True, res=None) -> None:
"""
plots the first n coefficients of B_n
"""
if res is not None:
self.res = res
self.y_data = np.linspace(0, self.res - 1, self.res)
self.x_data = [self.b.B_n(n) for n in self.x_data]
self.x_label = "n"
self.y_label = "B_n"
self.title = "The first {} coefficients of B_n".format(self.res)
self.figshow(self._fig)
def plot_K_n(self, res=None) -> None:
_ = np.linspace(0, self.res - 1, self.res)
if twoD_plot:
self.x_data = [self.b.B_n(int(n)).real for n in _]
self.x_label = "real part of B_n"
self.y_data = [self.b.B_n(int(n)).imag for n in _]
self.y_label = "imaginary part of B_n"
self.figshow(self._fig_complex)
else:
self.x_data = _
self.x_label = "n"
if real:
self.y_data = [self.b.B_n(int(n)).real for n in _]
self.y_label = "real part of B_n"
else:
self.y_data = [self.b.B_n(int(n)).imag for n in _]
self.y_label = "imaginary part of B_n"
self.figshow(self._fig_semilogy)
def plot_K_n(self, real=True, twoD_plot=True, res=None) -> None:
"""
plots the first n coefficients of K_n
"""
if res is not None:
self.res = res
self.x_data = np.linspace(0, self.res - 1, self.res)
self.y_data = [self.b.K_n(n) for n in self.x_data]
self.x_label = "n"
self.y_label = "K_n"
self.title = "The first {} coefficients of K_n".format(self.res)
self.figshow(self._fig)
def plot_M_n(self, res=None) -> None:
_ = np.linspace(0, self.res - 1, self.res)
if twoD_plot:
self.x_data = [self.b.K_n(int(n)).real for n in _]
self.x_label = "real part of K_n"
self.y_data = [self.b.K_n(int(n)).imag for n in _]
self.y_label = "imaginary part of K_n"
self.figshow(self._fig_complex)
else:
self.x_data = _
self.x_label = "n"
if real:
self.y_data = [self.b.K_n(int(n)).real for n in _]
self.y_label = "real part of K_n"
else:
self.y_data = [self.b.K_n(int(n)).imag for n in _]
self.y_label = "imaginary part of K_n"
self.figshow(self._fig_semilogy)
def plot_M_n(self, real=True, twoD_plot=True, res=None) -> None:
"""
plots the first n coefficients of M_n
"""
if res is not None:
self.res = res
self.x_data = np.linspace(0, self.res - 1, self.res)
self.y_data = [self.b.K_n(n) for n in self.x_data]
self.x_label = "n"
self.y_label = "M_n"
self.title = "The first {} coefficients of M_n".format(self.res)
self.figshow(self._fig)
_ = np.linspace(0, self.res - 1, self.res)
def plot_f1(self, res=None) -> None:
"""
plots the first n coefficients of f1
"""
if res is not None:
self.res = res
self.x_data = np.linspace(0, self.res - 1, self.res)
self.y_data = [self.b.f1 for n in self.x_data]
self.x_label = "n"
self.y_label = "f1"
self.title = "The first {} coefficients of f1".format(self.res)
self.figshow(self._fig)
if twoD_plot:
self.x_data = [self.b.M_n(int(n)).real for n in _]
self.x_label = "real part of M_n"
self.y_data = [self.b.M_n(int(n)).imag for n in _]
self.y_label = "imaginary part of M_n"
self.figshow(self._fig_complex)
else:
self.x_data = _
self.x_label = "n"
if real:
self.y_data = [self.b.M_n(int(n)).real for n in _]
self.y_label = "real part of M_n"
else:
self.y_data = [self.b.M_n(int(n)).imag for n in _]
self.y_label = "imaginary part of M_n"
self.figshow(self._fig_semilogy)
......@@ -56,6 +56,4 @@ class TestPlotVarious(BaseTest):
self.cls.R_0 = self.R0
def test_plot_various(self) -> None:
a = PlotAcoustofluidics(baseclass=self.cls, ARF=self.cls)
print(a.x_data)
a.plot_f1()
PlotAcoustofluidics(baseclass=self.cls)
Markdown is supported
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