def add_hline_to_plots(self): """Add horizontal lines to intersect vertical line""" for hLine in self.hLines: hLine.remove() self.hLines = [] self.lineToHLineDict = dict() for label in self.hLinesLabels: label.remove() self.hLinesLabels = [] for plot in self.plots: xVals, yVals, line, label = plot # Get the y-value of self.verticalLinePos index = Utilities.get_insertion_point_left(xVals, self.verticalLinePos) if index == len(xVals) or index == 0: continue x1, x, x2 = xVals[index - 1], self.verticalLinePos, xVals[index] y1, y2 = yVals[index - 1], yVals[index] # It holds xVals[index-1] < self.verticalLinePos <= xVals[index] fac = float(x - x2) / (x1 - x2) y = fac * y1 + (1 - fac) * y2 # this obviously only works if plots are piecewise linear axes = self.figure.gca() lowerBound, upperBound = axes.get_xlim() lineBeginFac = float(x - lowerBound) / (upperBound - lowerBound) hLine = axes.axhline(y=y, xmin=lineBeginFac, xmax=1, linewidth=self.verticalLineWidth) hLine.set_color(self.verticalLineColor) self.hLines.append(hLine) hLineText = axes.text(1.02, y, "%.2f" % y, va='center', ha="left", bbox=dict(facecolor="w", alpha=0.5), transform=axes.get_yaxis_transform()) hLineText.set_fontsize(8) self.hLinesLabels.append(hLineText) if not line.get_visible(): hLine.set_visible(False) hLineText.set_visible(False) self.lineToHLineDict[line] = (hLine, hLineText)
def get_approx_data(self, t): """ Returns approximated queue size and load at time t :param t: time :return: z_e(t), d_e(t), where entries can be "N/A" """ D = {'Queue size': "N/A", 'Load': "N/A"} for plot in self.plots: xVals, yVals, line, label = plot if label != 'Load' and label != "Queue size": continue index = Utilities.get_insertion_point_left(xVals, t) if index == len(xVals) or index == 0: continue else: x1, x, x2 = xVals[index - 1], t, xVals[index] y1, y2 = yVals[index - 1], yVals[index] # It holds: xVals[index-1] < t <= xVals[index] fac = float(x - x2) / (x1 - x2) y = fac * y1 + (1 - fac) * y2 # this obviously only works if plots are piecewise linear D[label] = y return D['Queue size'], D['Load']