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 24d6e31f authored by Cyrill Mast's avatar Cyrill Mast
Browse files

make attributes private

add matplotlib to requirements
parent e5a3c26a
import matplotlib.pyplot as plt
import numpy as np
from gorkov import PassiveVariable
class PlotGeneral:
def __init__(self):
self.resolution = 100
self.x_data = np.linspace(0, self.resolution - 1, self.resolution)
self.y_data = np.zeros(self.resolution)
self.x_label = ""
self.y_label = ""
self._x_data = PassiveVariable(
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")
self.fig, self.ax = plt.subplots()
self._x_label = PassiveVariable(
"", "The label in the x-direction")
self._y_label = PassiveVariable(
"", "The label in the y-direction")
self._title = PassiveVariable(
"", "The title")
self.plot()
self.update_labels("x_label", "y_label", "title")
self._fig, self._ax = plt.subplots()
self._ax.plot(self.x_data, self.y_data)
plt.style.use('ggplot')
......@@ -22,6 +30,51 @@ class PlotGeneral:
Define style options here
"""
@property
def x_data(self):
return self._x_data.value
@x_data.setter
def x_data(self, value):
self._ax.lines[0].set_xdata(value)
self._x_data.value = value
@property
def y_data(self):
return self._y_data.value
@y_data.setter
def y_data(self, value):
self._ax.lines[0].set_ydata(value)
self._y_data.value = value
@property
def x_label(self) -> str:
return self._x_label.value
@x_label.setter
def x_label(self, value):
self._ax.set_xlabel(value)
self._x_label.value = value
@property
def y_label(self) -> str:
return self._y_label.value
@y_label.setter
def y_label(self, value):
self._ax.set_ylabel(value)
self._y_label.value = value
@property
def title(self) -> str:
return self._title.value
@title.setter
def title(self, value):
self._ax.set_title(value)
self._title.value = value
def rescale(self, resolution=None):
"""
Implement this function
......@@ -33,11 +86,3 @@ class PlotGeneral:
"""
d_out = d_in
return d_out
def plot(self):
self.ax.plot(self.x_data, self.y_data)
def update_labels(self, x_label=None, y_label=None, title=None):
self.ax.set_title(title)
self.ax.set_xlabel(x_label, fontsize=10)
self.ax.set_ylabel(y_label, fontsize=10)
......@@ -19,13 +19,9 @@ class PlotVarious(PlotGeneral):
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.update_labels(
"n",
"A_n",
"The first {} coefficients of A_n".format(self.res))
self.plot()
self.x_label = "n"
self.y_label = "A_n"
self.title = "The first {} coefficients of A_n".format(self.res)
plt.show()
def plot_B_n(self, res=None) -> None:
......@@ -36,12 +32,9 @@ class PlotVarious(PlotGeneral):
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.update_labels(
"n",
"B_n",
"The first {} coefficients of B_n".format(self.res))
self.plot()
self.x_label = "n"
self.y_label = "B_n"
self.title = "The first {} coefficients of B_n".format(self.res)
plt.show()
def plot_K_n(self, res=None) -> None:
......@@ -52,12 +45,10 @@ class PlotVarious(PlotGeneral):
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.update_labels(
"n",
"K_n",
"The first {} coefficients of K_n".format(self.res))
self.x_label = "n"
self.y_label = "K_n"
self.title = "The first {} coefficients of K_n".format(self.res)
self.plot()
plt.show()
def plot_M_n(self, res=None) -> None:
......@@ -68,10 +59,20 @@ class PlotVarious(PlotGeneral):
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.update_labels(
"n",
"M_n",
"The first {} coefficients of M_n".format(self.res))
self.x_label = "n"
self.y_label = "M_n"
self.title = "The first {} coefficients of M_n".format(self.res)
plt.show()
self.plot()
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 = "M_n"
self.title = "The first {} coefficients of f1".format(self.res)
plt.show()
......@@ -58,4 +58,4 @@ class TestPlotVarious(BaseTest):
def test_plot_various(self) -> None:
a = PlotAcoustofluidics(baseclass=self.cls, ARF=self.cls)
print(a.x_data)
# a.plot_A_n(10)
a.plot_f1()
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