def mouseDoubleClickEvent(self, event):
        if not self.button_vcursor.isChecked():
            vals = []
            result = []
            inv = self.ax.transData.inverted()
            inv2 = self.ax2.transData.inverted()
            try:
                [time_ax, val_ax] = inv.transform((event.x(), self.frameSize().height() - event.y()))
            except IndexError:
                [time_ax, val_ax] = transformCoord2Log((event.x(), self.frameSize().height() - event.y()), self.ax,
                                                       self.ax2)
            t0, tmax = self.ax.get_xlim()

            for ax in self.fig.get_axes():
                for lines in ax.get_lines():
                    if self.isinDict(lines):
                        ind_t0 = indFinder(t0, lines.get_xdata())
                        ind_tmax = indFinder(tmax, lines.get_xdata())
                        step = 1 + (ind_tmax - ind_t0) / 400
                        ind = indFinder(time_ax, lines.get_xdata())

                        for i in range(ind - step, ind + step):
                            if i >= 0 and i < len(lines.get_xdata()):
                                try:
                                    new_coord = ax.transData.transform((lines.get_xdata()[i], lines.get_ydata()[i]))
                                except TypeError:
                                    new_coord = transformCoord2Log((lines.get_xdata()[i], lines.get_ydata()[i]),
                                                                   self.ax, self.ax2, inv=True)
                                if new_coord is not None:
                                    vals.append(np.sqrt((new_coord[0] - event.x()) ** 2 + (
                                        new_coord[1] - (self.frameSize().height() - event.y())) ** 2))
                                    result.append([lines.get_xdata()[i], lines.get_ydata()[i], ax, lines.get_label()])

            if result:
                label_point = QLabel(self)
                label_point.setWordWrap(True)
                point = result[np.argmin(vals)]
                txt = "%s \r\n" % point[3]
                if point[2].get_yscale() == "log":
                    txt += "%s \r\n % 0.3e" % (num2date(point[0]).strftime("%d/%m/%Y %H:%M:%S"), point[1])
                else:
                    txt += "%s \r\n % 0.2f" % (num2date(point[0]).strftime("%d/%m/%Y %H:%M:%S"), point[1])

                if label_point.width() + event.x() > self.frameSize().width():
                    label_point.move(event.x() - label_point.width(), event.y() - 16)
                else:
                    label_point.move(event.x(), event.y() - 16)
                line, = point[2].plot(point[0], point[1], 'o', color='k', markersize=4.)

                self.fig.canvas.restore_region(self.background)
                for ax in self.fig.get_axes():
                    for lines in ax.get_lines():
                        ax.draw_artist(lines)
                self.fig.canvas.blit(self.fig.bbox)
                label_point.setText(txt)
                label_point.show()

                timer = QTimer.singleShot(10000, partial(self.hidePoint, line, label_point, point[2]))
        def format_coord(x, y):

            display_coord = current.transData.transform((x, y))
            if not self.button_vcursor.isChecked():
                inv = other.transData.inverted()
                try:
                    ax_coord = inv.transform(display_coord)
                except IndexError:
                    ax_coord = transformCoord2Log(display_coord, other, current)

                if other.get_lines():
                    unit1 = "(%s)" % self.dictofline[other.get_lines()[0]].unit
                else:
                    return ""
                if current.get_lines():
                    unit2 = "(%s)" % self.dictofline[current.get_lines()[0]].unit
                else:
                    if unit1 == "(Torr)":
                        return ('{:<}   y1%s = {:<}'.format(
                            *[num2date(x).strftime("%a %d/%m  %H:%M:%S"), '{:.3e}'.format(ax_coord[1])])) % unit1
                    else:
                        return ('{:<}   y1%s = {:<}'.format(
                            *[num2date(x).strftime("%a %d/%m  %H:%M:%S"), '{:.2f}'.format(ax_coord[1])])) % unit1
                if unit1 == "(Torr)":
                    return ('{:<}   y1%s = {:<}   y2%s = {:<}'.format(
                        *[num2date(x).strftime("%a %d/%m  %H:%M:%S"), '{:.3e}'.format(ax_coord[1]),
                          '{:.2f}'.format(y)])) % (unit1, unit2)
                else:
                    return ('{:<}   y1%s = {:<}   y2%s = {:<}'.format(
                        *[num2date(x).strftime("%a %d/%m  %H:%M:%S"), '{:.3e}'.format(ax_coord[1]),
                          '{:.2f}'.format(y)])) % (unit1, unit2)
            else:
                self.verticalCursor(x, display_coord)
                return ""
    def verticalCursor(self, time, display_coord):

        i = 0
        res = []
        self.exceptCursor = False
        if hasattr(self, "linev"):
            try:
                self.fig.canvas.restore_region(self.background)
                self.linev.set_xdata((time, time))
                self.ax.draw_artist(self.linev)
                self.fig.canvas.blit(self.fig.bbox)

            except RuntimeError:
                self.exceptCursor = True
        else:
            self.linev = self.ax.axvline(time, visible=True)

        if not self.exceptCursor:
            for ax in self.fig.get_axes():
                for lines in ax.get_lines():
                    if self.isinDict(lines):
                        try:
                            ind = indFinder(time, lines.get_xdata())
                        except RuntimeError:
                            self.exceptCursor = True
                        except IndexError:
                            ind = len(lines.get_xdata()) - 1
                        if not self.exceptCursor:
                            if i == 0:
                                txt = (num2date(lines.get_xdata()[ind]).strftime("%d/%m/%Y %H:%M:%S") + "\r\n")
                                i += 1

                            if "pressure" in self.dictofline[lines].type and self.dictofline[lines].type[
                                                                             -2:] != "dt":
                                format = "%s : %0.3e \r\n"
                            else:
                                format = "%s : %0.2f \r\n"
                            try:
                                new_coord = ax.transData.transform((lines.get_xdata()[ind], lines.get_ydata()[ind]))
                            except TypeError:
                                new_coord = transformCoord2Log((lines.get_xdata()[ind], lines.get_ydata()[ind]),
                                                               self.ax, self.ax2, inv=True)

                            res.append([format, lines.get_label(), lines.get_ydata()[ind], new_coord[1]])
            res.sort(key=lambda row: row[3])
            txt += "".join(val[0] % (val[1], val[2]) for val in reversed(res))

            if not self.exceptCursor:
                if self.label_cursor.width() + display_coord[0] > self.frameSize().width():
                    self.label_cursor.move(display_coord[0] - self.label_cursor.width(), 200)
                else:
                    self.label_cursor.move(display_coord[0], 200)

                self.label_cursor.setText(txt)
                self.label_cursor.show()
        def format_coord(x, y):

            display_coord = current.transData.transform((x, y))
            if not self.button_vcursor.isChecked():
                inv = other.transData.inverted()
                try:
                    ax_coord = inv.transform(display_coord)
                except IndexError:
                    ax_coord = transformCoord2Log(display_coord, other,
                                                  current)

                if other.get_lines():
                    unit1 = "(%s)" % self.dictofline[other.get_lines()[0]].unit
                else:
                    return ""
                if current.get_lines():
                    unit2 = "(%s)" % self.dictofline[current.get_lines()
                                                     [0]].unit
                else:
                    if unit1 == "(Torr)":
                        return ('{:<}   y1%s = {:<}'.format(*[
                            num2date(x).strftime("%a %d/%m  %H:%M:%S"),
                            '{:.3e}'.format(ax_coord[1])
                        ])) % unit1
                    else:
                        return ('{:<}   y1%s = {:<}'.format(*[
                            num2date(x).strftime("%a %d/%m  %H:%M:%S"),
                            '{:.2f}'.format(ax_coord[1])
                        ])) % unit1
                if unit1 == "(Torr)":
                    return ('{:<}   y1%s = {:<}   y2%s = {:<}'.format(*[
                        num2date(x).strftime("%a %d/%m  %H:%M:%S"),
                        '{:.3e}'.format(ax_coord[1]), '{:.2f}'.format(y)
                    ])) % (unit1, unit2)
                else:
                    return ('{:<}   y1%s = {:<}   y2%s = {:<}'.format(*[
                        num2date(x).strftime("%a %d/%m  %H:%M:%S"),
                        '{:.3e}'.format(ax_coord[1]), '{:.2f}'.format(y)
                    ])) % (unit1, unit2)
            else:
                self.verticalCursor(x, display_coord)
                return ""
    def mouseDoubleClickEvent(self, event):
        if not self.button_vcursor.isChecked():
            vals = []
            result = []
            inv = self.ax.transData.inverted()
            inv2 = self.ax2.transData.inverted()
            try:
                [time_ax, val_ax] = inv.transform(
                    (event.x(), self.frameSize().height() - event.y()))
            except IndexError:
                [time_ax, val_ax] = transformCoord2Log(
                    (event.x(), self.frameSize().height() - event.y()),
                    self.ax, self.ax2)
            t0, tmax = self.ax.get_xlim()

            for ax in self.fig.get_axes():
                for lines in ax.get_lines():
                    if self.isinDict(lines):
                        ind_t0 = indFinder(t0, lines.get_xdata())
                        ind_tmax = indFinder(tmax, lines.get_xdata())
                        step = 1 + (ind_tmax - ind_t0) / 400
                        ind = indFinder(time_ax, lines.get_xdata())

                        for i in range(ind - step, ind + step):
                            if i >= 0 and i < len(lines.get_xdata()):
                                try:
                                    new_coord = ax.transData.transform(
                                        (lines.get_xdata()[i],
                                         lines.get_ydata()[i]))
                                except TypeError:
                                    new_coord = transformCoord2Log(
                                        (lines.get_xdata()[i],
                                         lines.get_ydata()[i]),
                                        self.ax,
                                        self.ax2,
                                        inv=True)
                                if new_coord is not None:
                                    vals.append(
                                        np.sqrt((new_coord[0] - event.x())**2 +
                                                (new_coord[1] -
                                                 (self.frameSize().height() -
                                                  event.y()))**2))
                                    result.append([
                                        lines.get_xdata()[i],
                                        lines.get_ydata()[i], ax,
                                        lines.get_label()
                                    ])

            if result:
                label_point = QLabel(self)
                label_point.setWordWrap(True)
                point = result[np.argmin(vals)]
                txt = "%s \r\n" % point[3]
                if point[2].get_yscale() == "log":
                    txt += "%s \r\n % 0.3e" % (num2date(
                        point[0]).strftime("%d/%m/%Y %H:%M:%S"), point[1])
                else:
                    txt += "%s \r\n % 0.2f" % (num2date(
                        point[0]).strftime("%d/%m/%Y %H:%M:%S"), point[1])

                if label_point.width() + event.x() > self.frameSize().width():
                    label_point.move(event.x() - label_point.width(),
                                     event.y() - 16)
                else:
                    label_point.move(event.x(), event.y() - 16)
                line, = point[2].plot(point[0],
                                      point[1],
                                      'o',
                                      color='k',
                                      markersize=4.)

                self.fig.canvas.restore_region(self.background)
                for ax in self.fig.get_axes():
                    for lines in ax.get_lines():
                        ax.draw_artist(lines)
                self.fig.canvas.blit(self.fig.bbox)
                label_point.setText(txt)
                label_point.show()

                timer = QTimer.singleShot(
                    10000, partial(self.hidePoint, line, label_point,
                                   point[2]))
    def verticalCursor(self, time, display_coord):

        i = 0
        res = []
        self.exceptCursor = False
        if hasattr(self, "linev"):
            try:
                self.fig.canvas.restore_region(self.background)
                self.linev.set_xdata((time, time))
                self.ax.draw_artist(self.linev)
                self.fig.canvas.blit(self.fig.bbox)

            except RuntimeError:
                self.exceptCursor = True
        else:
            self.linev = self.ax.axvline(time, visible=True)

        if not self.exceptCursor:
            for ax in self.fig.get_axes():
                for lines in ax.get_lines():
                    if self.isinDict(lines):
                        try:
                            ind = indFinder(time, lines.get_xdata())
                        except RuntimeError:
                            self.exceptCursor = True
                        except IndexError:
                            ind = len(lines.get_xdata()) - 1
                        if not self.exceptCursor:
                            if i == 0:
                                txt = (num2date(lines.get_xdata()[ind]).
                                       strftime("%d/%m/%Y %H:%M:%S") + "\r\n")
                                i += 1

                            if "pressure" in self.dictofline[
                                    lines].type and self.dictofline[
                                        lines].type[-2:] != "dt":
                                format = "%s : %0.3e \r\n"
                            else:
                                format = "%s : %0.2f \r\n"
                            try:
                                new_coord = ax.transData.transform(
                                    (lines.get_xdata()[ind],
                                     lines.get_ydata()[ind]))
                            except TypeError:
                                new_coord = transformCoord2Log(
                                    (lines.get_xdata()[ind],
                                     lines.get_ydata()[ind]),
                                    self.ax,
                                    self.ax2,
                                    inv=True)

                            res.append([
                                format,
                                lines.get_label(),
                                lines.get_ydata()[ind], new_coord[1]
                            ])
            res.sort(key=lambda row: row[3])
            txt += "".join(val[0] % (val[1], val[2]) for val in reversed(res))

            if not self.exceptCursor:
                if self.label_cursor.width(
                ) + display_coord[0] > self.frameSize().width():
                    self.label_cursor.move(
                        display_coord[0] - self.label_cursor.width(), 200)
                else:
                    self.label_cursor.move(display_coord[0], 200)

                self.label_cursor.setText(txt)
                self.label_cursor.show()
    def updateStyle(self):
        lns = []
        labs = []
        vmax = []
        self.ax.set_xlabel('Time')
        for i, ax in enumerate(self.fig.get_axes()):
            if ax.get_lines():
                ax.set_ylabel(self.dictofline[ax.get_lines()[0]].ylabel,
                              color=self.dictofline[ax.get_lines()[0]].color)
                for tick in ax.yaxis.get_major_ticks():
                    if i == 0:
                        tick.label1On = True
                        tick.label2On = False
                        tick.label1.set_color(
                            color=self.dictofline[ax.get_lines()[0]].color)
                        self.ax2.grid(which='major', alpha=0.0)
                        ax.grid(which='major',
                                alpha=0.5,
                                color=self.dictofline[ax.get_lines()[0]].color)
                        ax.grid(which='minor',
                                alpha=0.25,
                                color=self.dictofline[ax.get_lines()[0]].color,
                                linestyle='--')
                    elif i == 1:
                        tick.label1On = False
                        tick.label2On = True
                        tick.label2.set_color(
                            color=self.dictofline[ax.get_lines()[0]].color)
                        ax.grid(which='major',
                                alpha=1.0,
                                color=self.dictofline[ax.get_lines()[0]].color,
                                linestyle='dashdot')
                for lines in ax.get_lines():
                    if self.isinDict(lines):
                        t0, tmax = self.ax.get_xlim()
                        ind = indFinder(tmax, lines.get_xdata())
                        try:
                            new_coord = ax.transData.transform(
                                (lines.get_xdata()[ind],
                                 lines.get_ydata()[ind]))
                        except TypeError:
                            new_coord = transformCoord2Log(
                                (lines.get_xdata()[ind],
                                 lines.get_ydata()[ind]),
                                self.ax,
                                self.ax2,
                                inv=True)

                        vmax.append([new_coord[1], lines.get_label(), lines])
                        self.setLineStyle(lines)

                if ax.get_yscale() in ["log", "symlog"]:
                    subs = [1.0, 2.0, 3.0, 6.0]  # ticks to show per decade
                    ax.yaxis.set_minor_locator(
                        ticker.LogLocator(subs=subs))  # set the ticks position
                else:
                    minor_locatory = ticker.AutoMinorLocator(5)
                    ax.yaxis.set_minor_locator(minor_locatory)
                    ax.get_yaxis().get_major_formatter().set_useOffset(False)

                minor_locatorx = ticker.AutoMinorLocator(5)
                ax.xaxis.set_minor_locator(minor_locatorx)

            else:
                ax.set_ylabel("")
                for tick in ax.yaxis.get_major_ticks():
                    tick.label1On = False
                    tick.label2On = False

        vmax.sort(key=lambda row: row[0])
        for [v, labels, lines] in reversed(vmax):
            lns.append(lines)
            labs.append(labels)

        if len(lns) < 7:
            size = 10
        else:
            size = 10 - 0.82 * len(lns) / 7
        self.ax.legend(lns, labs, loc=0, prop={'size': size})
    def updateStyle(self):
        lns = []
        labs = []
        vmax = []
        self.ax.set_xlabel('Time')
        for i, ax in enumerate(self.fig.get_axes()):
            if ax.get_lines():
                ax.set_ylabel(self.dictofline[ax.get_lines()[0]].ylabel, color=self.dictofline[ax.get_lines()[0]].color)
                for tick in ax.yaxis.get_major_ticks():
                    if i == 0:
                        tick.label1On = True
                        tick.label2On = False
                        tick.label1.set_color(color=self.dictofline[ax.get_lines()[0]].color)
                        self.ax2.grid(which='major', alpha=0.0)
                        ax.grid(which='major', alpha=0.5, color=self.dictofline[ax.get_lines()[0]].color)
                        ax.grid(which='minor', alpha=0.25, color=self.dictofline[ax.get_lines()[0]].color,
                                linestyle='--')
                    elif i == 1:
                        tick.label1On = False
                        tick.label2On = True
                        tick.label2.set_color(color=self.dictofline[ax.get_lines()[0]].color)
                        ax.grid(which='major', alpha=1.0, color=self.dictofline[ax.get_lines()[0]].color,
                                linestyle='dashdot')
                for lines in ax.get_lines():
                    if self.isinDict(lines):
                        t0, tmax = self.ax.get_xlim()
                        ind = indFinder(tmax, lines.get_xdata())
                        try:
                            new_coord = ax.transData.transform((lines.get_xdata()[ind], lines.get_ydata()[ind]))
                        except TypeError:
                            new_coord = transformCoord2Log((lines.get_xdata()[ind], lines.get_ydata()[ind]), self.ax,
                                                           self.ax2, inv=True)

                        vmax.append([new_coord[1], lines.get_label(), lines])
                        self.setLineStyle(lines)

                if ax.get_yscale() in ["log", "symlog"]:
                    subs = [1.0, 2.0, 3.0, 6.0]  # ticks to show per decade
                    ax.yaxis.set_minor_locator(ticker.LogLocator(subs=subs))  # set the ticks position
                else:
                    minor_locatory = ticker.AutoMinorLocator(5)
                    ax.yaxis.set_minor_locator(minor_locatory)
                    ax.get_yaxis().get_major_formatter().set_useOffset(False)

                minor_locatorx = ticker.AutoMinorLocator(5)
                ax.xaxis.set_minor_locator(minor_locatorx)

            else:
                ax.set_ylabel("")
                for tick in ax.yaxis.get_major_ticks():
                    tick.label1On = False
                    tick.label2On = False

        vmax.sort(key=lambda row: row[0])
        for [v, labels, lines] in reversed(vmax):
            lns.append(lines)
            labs.append(labels)

        if len(lns) < 7:
            size = 10
        else:
            size = 10 - 0.82 * len(lns) / 7
        self.ax.legend(lns, labs, loc=0, prop={'size': size})