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 583e4cc commit 62fc221
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions src/mlpro/bf/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
## -- - 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
## -- 2024-06-24 2.14.0 DA New auto-managed attribute Plottable._plot_first_time : bool
## -------------------------------------------------------------------------------------------------

"""
Expand Down Expand Up @@ -235,8 +233,7 @@ 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
self._plot_first_time : bool = True


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

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

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

# 1 Plot functionality turned on? Initialization already called?
if ( not self.C_PLOT_ACTIVE ) or ( not self._visualize ) or self._plot_initialized: return
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

plt.ioff()

Expand All @@ -311,7 +319,6 @@ 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 Down Expand Up @@ -404,17 +411,20 @@ def refresh_plot(self, p_force:bool=False):
"""

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


# 2 Object has own figure or refresh is forced by caller?
# 1 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)


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


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

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

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

# 2 Call of all required plot methods
view = self._plot_settings.view
Expand All @@ -516,8 +532,6 @@ 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 @@ -579,15 +593,20 @@ def remove_plot(self, p_refresh:bool = True):
"""

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

# 2 Call _remove_plot method of current view
view = self._plot_settings.view
self._plot_methods[view][2]()

# 3 Optionally refresh
if p_refresh: self.refresh_plot(p_force=False)


self._plot_first_time = True


## -------------------------------------------------------------------------------------------------
def _remove_plot_2d(self):
Expand Down

0 comments on commit 62fc221

Please sign in to comment.