Skip to content

Commit

Permalink
Working newer setup without subplots
Browse files Browse the repository at this point in the history
Signed-off-by: Sietze van Buuren <[email protected]>
  • Loading branch information
swvanbuuren committed Jun 30, 2024
1 parent e915ec4 commit a2c717b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
5 changes: 3 additions & 2 deletions mlpyqtgraph/ml_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def close(figure_ref):

def plot(*args, **kwargs):
""" Plots into the current axis """
gcf().create_axis(axis_type='2D')
return gca().add(*args, **kwargs)


Expand All @@ -46,6 +47,6 @@ def legend(*args):

def surf(*args, **kwargs):
""" Plots a 3D surface """
if gcf().change_layout('Qt'):
gcf().add_axis(axis_type='3D')
gcf().change_layout('Qt')
gcf().create_axis(axis_type='3D')
gca().add(*args, **kwargs)
12 changes: 8 additions & 4 deletions mlpyqtgraph/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ def getItem(self, row, column):
""" Returns the item at row, col. If empty return None """
return self.layout().itemAtPosition(row, column)

def addItem(self, item, row, column, rowSpan=1, columnSpan=1):
def addItem(self, item, row=0, column=0, rowSpan=1, columnSpan=1):
""" Adds an item at row, col with rowSpand and colSpan """
self.layout().addWidget(item, row, column, rowSpan, columnSpan)

def removeItem(self, item):
""" Removes an item from the layout """
self.layout().removeItem(item)


class FigureWindow(QtCore.QObject):
""" Controls a figure window instance """
Expand Down Expand Up @@ -78,10 +82,10 @@ def change_layout(self, layout_type='pg'):
self.window.setCentralWidget(LayoutWidget())
return True

def set_axis(self, index, row=0, column=0, row_span=1, column_span=1):
""" Creates an axis and return its index """
def add_axis(self, index):
""" Adds an axis to the figure """
axis = controllers.gui_refs.get('axis').items[index]
self.graphics_layout.addItem(axis, row, column, row_span, column_span)
self.graphics_layout.addItem(axis)

@property
def graphics_layout(self):
Expand Down
14 changes: 6 additions & 8 deletions mlpyqtgraph/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,19 @@ class FigureWorker(containers.WorkerItem):
height = factory.attribute()
raise_window = factory.method()
change_layout = factory.method()
set_axis = factory.method()
add_axis = factory.method()
has_axis = factory.method()

def __init__(self, *args, **kwargs):
self.axis = None
super().__init__(*args, **kwargs)
self.add_axis()

def add_axis(self, *args, **kwargs):
def create_axis(self, *args, **kwargs):
""" Adds an axis to the figure worker """
axis_container = controllers.worker_refs.get('axis')
if self.axis:
remove_axis = self.axis
self.axis = None
axis_container.close(remove_axis)
return
axis_container = controllers.worker_refs.get('axis')
axis = axis_container.create(**kwargs)
index = axis.index
self.set_axis(index)
self.add_axis(index)
self.axis = axis

0 comments on commit a2c717b

Please sign in to comment.