Skip to content

Commit

Permalink
Add labels to GUI df curve plot.
Browse files Browse the repository at this point in the history
  • Loading branch information
NikoOinonen committed Dec 2, 2024
1 parent 12a9034 commit af0ccf7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
32 changes: 24 additions & 8 deletions ppafm/GUIWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,28 @@ def show_warning(parent, text, title="Warning!"):
class FigCanvas(FigureCanvasQTAgg):
"""A canvas that updates itself every second with a new plot."""

def __init__(self, parentWiget=None, parentApp=None, width=5, height=4, dpi=100):
def __init__(self, parentWiget=None, parentApp=None, width=5, height=4, dpi=100, xlabel=None, ylabel=None):
self.fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = self.fig.add_subplot(111)
self.set_labels(xlabel, ylabel)
FigureCanvasQTAgg.__init__(self, self.fig)
self.parent = parentApp
self.setParent(parentWiget)
FigureCanvasQTAgg.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
FigureCanvasQTAgg.updateGeometry(self)

def clear(self):
self.axes.cla()
self.set_labels(self.xlabel, self.ylabel)

def set_labels(self, xlabel=None, ylabel=None):
self.xlabel = xlabel
self.ylabel = ylabel
if xlabel:
self.axes.set_xlabel(xlabel)
if ylabel:
self.axes.set_ylabel(ylabel)


# =======================
# FigLinePlot
Expand All @@ -78,8 +91,8 @@ def __init__(self, parentWiget=None, parentApp=None, width=5, height=4, dpi=100)
class FigPlot(FigCanvas):
"""A canvas that updates itself every second with a new plot."""

def __init__(self, parentWiget=None, parentApp=None, width=5, height=4, dpi=100):
super(self.__class__, self).__init__(parentWiget=parentWiget, parentApp=parentApp, width=width, height=height, dpi=dpi)
def __init__(self, parentWiget=None, parentApp=None, width=5, height=4, dpi=100, xlabel=None, ylabel=None):
super(self.__class__, self).__init__(parentWiget=parentWiget, parentApp=parentApp, width=width, height=height, dpi=dpi, xlabel=xlabel, ylabel=ylabel)
self.defaultPlotAxis()

def defaultPlotAxis(self):
Expand All @@ -89,6 +102,11 @@ def plotDatalines(self, x, y, label):
self.axes.plot(x, y, "x-", label=label)
self.draw()

def clear(self):
super().clear()
self.defaultPlotAxis()
self.draw()


# =======================
# FigLinePlot
Expand Down Expand Up @@ -262,9 +280,9 @@ def __init__(self, parent=None, title="SlaveWindow"):


class PlotWindow(SlaveWindow):
def __init__(self, parent=None, title="PlotWindow", width=5, height=4, dpi=100):
def __init__(self, parent=None, title="PlotWindow", width=5, height=4, dpi=100, xlabel=None, ylabel=None):
super(self.__class__, self).__init__(parent=parent, title=title)
self.figCan = FigPlot(parent, width=width, height=height, dpi=dpi)
self.figCan = FigPlot(parent, width=width, height=height, dpi=dpi, xlabel=xlabel, ylabel=ylabel)
self.centralLayout.addWidget(self.figCan)

vb = QtWidgets.QHBoxLayout()
Expand Down Expand Up @@ -322,9 +340,7 @@ def save_png(self):
self.figCan.fig.savefig(fileName, bbox_inches="tight")

def clearFig(self):
self.figCan.axes.cla()
self.figCan.defaultPlotAxis()
self.figCan.draw()
self.figCan.clear()
self.parent.clearPoints()

def setRange(self):
Expand Down
2 changes: 1 addition & 1 deletion ppafm/cli/gui/ppafm_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def __init__(self, input_files=None, device=0, verbose=0):
self._create_buttons_ui()

# Create curve plotting window
self.figCurv = guiw.PlotWindow(parent=self, width=5, height=4, dpi=100)
self.figCurv = guiw.PlotWindow(parent=self, width=5, height=4, dpi=100, xlabel="z_tip (Å)", ylabel="df (Hz)")

if input_files:
self.loadInput(**input_files)
Expand Down

0 comments on commit af0ccf7

Please sign in to comment.