Skip to content

Commit

Permalink
OA: Design updates on cluster analysis #1015
Browse files Browse the repository at this point in the history
  • Loading branch information
detlefarend committed Jun 24, 2024
1 parent c49241f commit 583e4cc
Showing 1 changed file with 19 additions and 33 deletions.
52 changes: 19 additions & 33 deletions src/mlpro/bf/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@
## -- - new parameter data_horizon with default value 1000
## -- 2024-05-22 2.13.0 DA New method PlotSettings.copy()
## -- 2024-06-04 2.13.1 DA/SK Turned on TKAgg for Mac
## -- 2024-06-24 2.14.0 DA Refactoring/code optimization:
## -- - calling Plottable.__init__() is mandatory now
## -- - new auto-managed attribute Plottable._plot_first_time : bool
## -------------------------------------------------------------------------------------------------

"""
Ver. 2.13.1 (2024-06-04)
Ver. 2.14.0 (2024-06-24)
This module provides various classes related to data plotting.
Expand Down Expand Up @@ -232,6 +235,8 @@ class Plottable:
def __init__(self, p_visualize:bool=False):
self._visualize = self.C_PLOT_ACTIVE and p_visualize
self._plot_settings : PlotSettings = None
self._plot_initialized : bool = False
self._plot_first_time : bool = True


## -------------------------------------------------------------------------------------------------
Expand All @@ -251,10 +256,7 @@ def set_plot_settings(self, p_plot_settings : PlotSettings ):
C_PLOT_DEFAULT_VIEW).
"""

try:
if self._plot_initialized: return
except:
pass
if self._plot_initialized: return

if p_plot_settings is not None:
self._plot_settings = p_plot_settings
Expand Down Expand Up @@ -287,15 +289,7 @@ def init_plot( self,
"""

# 1 Plot functionality turned on? Initialization already called?
try:
if ( not self.C_PLOT_ACTIVE ) or ( not self._visualize ): return
except:
return

try:
if self._plot_initialized: return
except:
self._plot_own_figure = False
if ( not self.C_PLOT_ACTIVE ) or ( not self._visualize ) or self._plot_initialized: return

plt.ioff()

Expand All @@ -317,6 +311,7 @@ def init_plot( self,
self._plot_own_figure = True
else:
self._figure : Figure = p_figure
self._plot_own_figure = False


# 4 Call of all initialization methods of the required views
Expand All @@ -340,6 +335,7 @@ def init_plot( self,

# 6 Marker to ensure that initialization runs only once
self._plot_initialized = True
self._plot_first_time = True


## -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -408,20 +404,17 @@ def refresh_plot(self, p_force:bool=False):
"""

# 1 Plot functionality turned on?
try:
if ( not self.C_PLOT_ACTIVE ) or ( not self._visualize ): return
except:
return
if ( not self.C_PLOT_ACTIVE ) or ( not self._visualize ): return


# 1 Object has own figure or refresh is forced by caller?
# 2 Object has own figure or refresh is forced by caller?
if not self._plot_own_figure and not p_force: return

if self._plot_own_figure:
self._plot_step_counter = mod(self._plot_step_counter+1, self._plot_settings.step_rate)


# 2 Refresh plot
# 3 Refresh plot
if ( self._plot_step_counter==0 ) or p_force: self._refresh_plot()


Expand Down Expand Up @@ -511,16 +504,10 @@ def update_plot(self, **p_kwargs):
"""

# 0 Plot functionality turned on?
try:
if ( not self.C_PLOT_ACTIVE ) or ( not self._visualize ): return
except:
return
if ( not self.C_PLOT_ACTIVE ) or ( not self._visualize ): return

# 1 Plot already initialized?
try:
if not self._plot_initialized: self.init_plot()
except:
self.init_plot()
# 1 Plot already initialized?
if not self._plot_initialized: self.init_plot()

# 2 Call of all required plot methods
view = self._plot_settings.view
Expand All @@ -529,6 +516,8 @@ def update_plot(self, **p_kwargs):
# 3 Update content of own(!) figure after self._plot_step_rate calls
self.refresh_plot(p_force=False)

self._plot_first_time = False


## -------------------------------------------------------------------------------------------------
def _update_plot_2d(self, p_settings:PlotSettings, **p_kwargs):
Expand Down Expand Up @@ -590,10 +579,7 @@ def remove_plot(self, p_refresh:bool = True):
"""

# 1 Plot functionality turned on?
try:
if ( not self.C_PLOT_ACTIVE ) or ( not self._visualize ): return
except:
return
if ( not self.C_PLOT_ACTIVE ) or ( not self._visualize ): return

# 2 Call _remove_plot method of current view
view = self._plot_settings.view
Expand Down

0 comments on commit 583e4cc

Please sign in to comment.