Switch from per-channel to global background color

Figure-global backgrounds are reasonably fast, while axes-specific
background color causes performance drop.
pull/357/head
nyanpasu64 2018-08-15 17:26:20 -07:00
rodzic b648f9755b
commit 0968052566
2 zmienionych plików z 7 dodań i 10 usunięć

Wyświetl plik

@ -18,7 +18,6 @@ class ChannelConfig:
render_width_ratio: int = 1
ampl_ratio: float = 1.0 # TODO use amplification = None instead?
bg_color: Any = None
line_color: Any = None

Wyświetl plik

@ -18,12 +18,13 @@ if TYPE_CHECKING:
from ovgenpy.channel import ChannelConfig
@register_config(always_dump='init_bg_color init_line_color line_width')
@register_config(always_dump='bg_color init_line_color line_width')
class RendererConfig:
width: int
height: int
init_bg_color: Any = 'black'
bg_color: Any = 'black'
init_line_color: Any = 'white'
# line_width: Optional[float] = None # TODO
@ -63,7 +64,6 @@ class MatplotlibRenderer:
self.axes: List['Axes'] = None # set by set_layout()
self.lines: List['Line2D'] = None # set by render_frame() first call
self.bg_colors: List = [None] * nplots
self.line_colors: List = [None] * nplots
self._set_layout() # mutates self
@ -81,7 +81,7 @@ class MatplotlibRenderer:
# https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots.html
if self.fig:
raise Exception("I don't currently expect to call set_layout() twice")
plt.close(self.fig)
# plt.close(self.fig)
axes2d: np.ndarray['Axes']
self.fig, axes2d = plt.subplots(
@ -93,7 +93,7 @@ class MatplotlibRenderer:
# remove Axis from Axes
for ax in axes2d.flatten():
ax.set_axis_off() # FIXME ax.get_xaxis().set_visible(False)
ax.set_axis_off()
# Generate arrangement (using nplots, cfg.orientation)
self.axes = self.layout.arrange(lambda row, col: axes2d[row, col])
@ -112,8 +112,6 @@ class MatplotlibRenderer:
raise ValueError(
f"cannot assign {len(channel_cfgs)} colors to {self.nplots} plots"
)
self.bg_colors = [coalesce(cfg.bg_color, self.cfg.init_bg_color)
for cfg in channel_cfgs]
self.line_colors = [coalesce(cfg.line_color, self.cfg.init_line_color)
for cfg in channel_cfgs]
@ -125,17 +123,17 @@ class MatplotlibRenderer:
# Initialize axes and draw waveform data
if self.lines is None:
self.fig.set_facecolor(self.cfg.bg_color)
self.lines = []
for idx, data in enumerate(datas):
# Setup colors
bg_color = self.bg_colors[idx]
line_color = self.line_colors[idx]
# Setup axes
ax = self.axes[idx]
ax.set_xlim(0, len(data) - 1)
ax.set_ylim(-1, 1)
ax.set_facecolor(bg_color)
# Plot line
line = ax.plot(data, color=line_color)[0]