Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add labels to GUI df curve plot. #319

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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