Skip to content

Sliders

Slider

Slider

Internal class. Manages sliders.

Integrated via method add_slider in: - Map1D - Cobweb - PhasePortrait2D - PhasePotrait3D - Trajectory2D - Trajectory3D

Methods

  • call : Updates internal dF_args and replots the graphs.
Source code in phaseportrait/sliders/sliders.py
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
class Slider():
    """
    Slider
    ------
    Internal class. Manages sliders.

    Integrated via method `add_slider` in:
    - Map1D
    - Cobweb
    - PhasePortrait2D
    - PhasePotrait3D
    - Trajectory2D
    - Trajectory3D

    Methods
    -------
    * __call__ :  Updates internal dF_args and replots the graphs.
    """
    def __init__(self, portrait, param_name, valinit=None, valstep=0.1, valinterval=[]):
        """
        Slider
        ------
        Internal class. Manages sliders.

        Parameters
        ----------
        portrait : 
            Class that uses the Slider.
        param_name : str
            Name of the parameter to slide over.
        valinit : float
            Initial value of the parameter in the slider.
        valsetp : float, default=0.1
            Precision of the slider.
        valinterval : Union[float, list]
            Parameter range in the slider.
        """

        self.portrait = portrait
        self.param_name = param_name
        self.value = valinit

        valinterval = utils.construct_interval_1d(valinterval)
        valinterval = np.array(valinterval)

        if 'Trajectory' in self.portrait._name_ or 'Cobweb' in self.portrait._name_: 
            self.ax = self.portrait.sliders_fig.add_axes([0.25, 0.88 - 0.05*len(self.portrait.sliders), 0.4, 0.05])

        if 'PhasePortrait' in self.portrait._name_ or 'Map1D' in self.portrait._name_:
            self.ax = self.portrait.fig.add_axes([0.25, 0.015 + 0.05*len(self.portrait.sliders), 0.4, 0.03])

        aux = {'valinit':valinit} if isinstance(self.value, (int, float)) else {}
        self.slider = matplot_slider(self.ax, self.param_name, *valinterval, valstep=valstep, **aux)

    def __call__(self, value):
        """
        Updates internal dF_args and replots the graphs.

        Arguments
        ---------
        value : float
            New value for the parameter of the slider
        """

        ax = self.portrait.ax 
        if isinstance(ax, dict):
            legend = {}
            for k in ax.keys():
                legend.update({k: ax[k].get_legend()})

        else:
            legend = ax.get_legend()

        if isinstance(ax, dict):
            for k in ax.keys():
                ax[k].cla()
        else:
            ax.cla()

        self.value = value

        if 'Cobweb' in self.portrait._name_:
            self.portrait.update_dF_args()

        if isinstance(ax, dict):
            for k in ax.keys():
                ax[k].legend_ = legend[k]
        else:
            ax.legend_ = legend

        self.portrait.plot()

    def update_slider_ends(self, valmin, valmax):
        """
        Updates slider min and max values

        Parameters
        ----------
        valmin : float
            Min slider value
        valmax : float
            Max slider value
        """
        self.slider.valmin = valmin
        self.slider.valmax = valmax

__call__(value)

Updates internal dF_args and replots the graphs.

Arguments
float

New value for the parameter of the slider

Source code in phaseportrait/sliders/sliders.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def __call__(self, value):
    """
    Updates internal dF_args and replots the graphs.

    Arguments
    ---------
    value : float
        New value for the parameter of the slider
    """

    ax = self.portrait.ax 
    if isinstance(ax, dict):
        legend = {}
        for k in ax.keys():
            legend.update({k: ax[k].get_legend()})

    else:
        legend = ax.get_legend()

    if isinstance(ax, dict):
        for k in ax.keys():
            ax[k].cla()
    else:
        ax.cla()

    self.value = value

    if 'Cobweb' in self.portrait._name_:
        self.portrait.update_dF_args()

    if isinstance(ax, dict):
        for k in ax.keys():
            ax[k].legend_ = legend[k]
    else:
        ax.legend_ = legend

    self.portrait.plot()

__init__(portrait, param_name, valinit=None, valstep=0.1, valinterval=[])

Slider

Internal class. Manages sliders.

Parameters
portrait

Class that uses the Slider.

str

Name of the parameter to slide over.

float

Initial value of the parameter in the slider.

float, default=0.1

Precision of the slider.

Union[float, list]

Parameter range in the slider.

Source code in phaseportrait/sliders/sliders.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def __init__(self, portrait, param_name, valinit=None, valstep=0.1, valinterval=[]):
    """
    Slider
    ------
    Internal class. Manages sliders.

    Parameters
    ----------
    portrait : 
        Class that uses the Slider.
    param_name : str
        Name of the parameter to slide over.
    valinit : float
        Initial value of the parameter in the slider.
    valsetp : float, default=0.1
        Precision of the slider.
    valinterval : Union[float, list]
        Parameter range in the slider.
    """

    self.portrait = portrait
    self.param_name = param_name
    self.value = valinit

    valinterval = utils.construct_interval_1d(valinterval)
    valinterval = np.array(valinterval)

    if 'Trajectory' in self.portrait._name_ or 'Cobweb' in self.portrait._name_: 
        self.ax = self.portrait.sliders_fig.add_axes([0.25, 0.88 - 0.05*len(self.portrait.sliders), 0.4, 0.05])

    if 'PhasePortrait' in self.portrait._name_ or 'Map1D' in self.portrait._name_:
        self.ax = self.portrait.fig.add_axes([0.25, 0.015 + 0.05*len(self.portrait.sliders), 0.4, 0.03])

    aux = {'valinit':valinit} if isinstance(self.value, (int, float)) else {}
    self.slider = matplot_slider(self.ax, self.param_name, *valinterval, valstep=valstep, **aux)

update_slider_ends(valmin, valmax)

Updates slider min and max values

Parameters
float

Min slider value

float

Max slider value

Source code in phaseportrait/sliders/sliders.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
def update_slider_ends(self, valmin, valmax):
    """
    Updates slider min and max values

    Parameters
    ----------
    valmin : float
        Min slider value
    valmax : float
        Max slider value
    """
    self.slider.valmin = valmin
    self.slider.valmax = valmax