Skip to content

Commit

Permalink
Remember max y_lim across all plots
Browse files Browse the repository at this point in the history
This avoids the current plot truncating the view for plots with higher points.
  • Loading branch information
rbaltrusch committed Jun 22, 2024
1 parent ace52e6 commit f119ed9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bach_generator/gui/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def y_limits(self):
@staticmethod
def _get_limits(array):
"""returns tuple of min and max of passed array. defaults to (0, 1)"""
return (0, 1) if array is None else (min(array), max(array))
return (0, 1) if array is None else (min(array), max(array) * 1.1)


class Figure:
Expand All @@ -67,9 +67,10 @@ def __init__(self, parent, bg_colour, axes_colour):
self.tk_widget = self.canvas.get_tk_widget()
rect = self.figure.patch
rect.set_facecolor(self.bg_colour)
self._y_lim = 0

# pylint: disable=disallowed-name #bar
def plot(self, *datasets, normalized=False, annotate=False, bar=False):
def plot(self, *datasets: DataSet, normalized=False, annotate=False, bar=False):
"""Plots the passed datasets.
If normalized=True, the datasets are normalized first.
If annotate=True, each point in the datasets gets annotated with custom text
Expand All @@ -85,14 +86,16 @@ def plot(self, *datasets, normalized=False, annotate=False, bar=False):
list(range(len(dataset.y))), dataset.y, color=dataset.line_colour
)
else:
self.axes.plot(*dataset)
self.axes.plot(*dataset, color=dataset.line_colour)

self.axes.set_xlim(*dataset.x_limits)

if normalized:
self.axes.set_yticks([x * 0.2 for x in range(7)]) # 0 to 1.2
else:
self.axes.set_ylim(*dataset.y_limits)
# remember y lims from previous plots
self._y_lim = max(self._y_lim, dataset.y_limits[1])
self.axes.set_ylim(0, self._y_lim)

if annotate and dataset.annotations:
# adjust for center alignment of bars
Expand Down

0 comments on commit f119ed9

Please sign in to comment.