Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.1 kB
3
Indexable
Never
class myCanvas(FigureCanvasQTAgg):
    def __init__(self, parent=None, width=11, height=5, dpi=100):
        self.fig = Figure(figsize=(width, height), dpi=dpi)
        super(myCanvas,self).__init__(self.fig)
        self.setParent(parent)
        self.axes1 = self.fig.add_subplot(111)

    def update_canvas(self, *args, **kwargs):
        # super().print_figure(*args, **kwargs)
        # self.draw()
        self.fig.canvas.draw()
        self.fig.canvas.flush_events()

    def plot(self, signal, ax, ymin=-1, ymax=2, title='', fill_between=None):
        ax.clear()
        ax.set_title(title)
        ax.set_ylim([ymin, ymax])
        ax.plot(signal)
        if fill_between:
            ax.fill_between(
                np.arange(
                    fill_between[0], fill_between[1], 1), ymin, ymax, color='orange', alpha=0.2)
        # ax.scatter(len(signal)//2, signal[len(signal)//2], color='red', alpha=0.7)

    def write_text(self, ax, x, y, content, color='black', fontsize=12, alpha=1.0):
        ax.text(
            x, y + 0.2, content, 
            color=color, fontsize=fontsize, alpha=alpha)