From 3311e43ef55bd13e438824e48f169d8cd27785d7 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong" Date: Fri, 15 Jun 2018 09:09:27 +0200 Subject: [PATCH] Bugfix in bar plot when ylim[0] is not zero --- lasp/plot/bar.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lasp/plot/bar.py b/lasp/plot/bar.py index bedc0d7..6b3a791 100644 --- a/lasp/plot/bar.py +++ b/lasp/plot/bar.py @@ -279,6 +279,18 @@ class BarScene(QGraphicsScene): return (n*(self.G*L+dxbars*L) + xL + self.G*L/2) def getBarRect(self, n, g, yval): + """ + Returns a bar QRectF. + + Args: + n: Bar index (i.e. corresponding to a certain frequency band) + g: Bar group (i.e. corresponding to a certain quantity) + yval: Height of bar, 1 for full lenght, 0 for no length + + Returns: + QRectF corresponding to the bar at the right place in the scene + """ + assert yval >= 0 and yval <= 1, "Invalid yval" Lx = self.xsize-rightoffset-leftoffset Ly = self.ysize-topoffset - bottomoffset @@ -326,9 +338,12 @@ class BarScene(QGraphicsScene): assert newydata.shape[0] == N assert newydata.shape[1] == G - # Crop values to be between 0 and 1 + # Y-values of the bars should be between 0 and 1. scalefac = self.ylim[1]-self.ylim[0] - yvals = np.clip(newydata, self.ylim[0], self.ylim[1])/scalefac + yvals = (newydata - self.ylim[0])/scalefac + + # Clip values to be between 0 and 1 + yvals = np.clip(yvals, 0, 1) for g in range(G): color = self.colors[g]