I have a helper class in my gui.py file:
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
class MplCanvas(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
self.fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = self.fig.add_subplot(111)
super(MplCanvas, self).__init__(self.fig)
I also have a main window class in gui.py: class MainWidget(QWidget)
In which there are three objects of the above MplCanvas class
: self.image1
, self.image2
, self.image3
These three objects draw pictures through the same function: visual.draw_image
, which is located in the visual.py file. In this function, in addition to the main axes ax
, another axes dax = ax.twinx()
is created.
The images are updated by the update_images
function, called when the button is clicked.
Every time I needed to update the picture, I tried three ways to clear my axes / shape / MplCanvas() object / etc:
1.
self.image1.axes.clear()
self.image2.axes.clear()
self.image3.axes.clear()
for ax in self.image1.axes.get_shared_x_axes().get_siblings(self.image1.axes):
ax.clear()
for ax in self.image2.axes.get_shared_x_axes().get_siblings(self.image2.axes):
ax.clear()
for as in self.image3.axes.get_shared_x_axes().get_siblings(self.image3.axes):
ax.clear()
self.image1.fig.canvas.draw()
self.image2.fig.canvas.draw()
self.image3.fig.canvas.draw()
So, in the first case, the right dax
axes is displayed twice from two pictures, in the second case, the right dax
axes from the first picture is cleared, but at the same time a new one is drawn – completely new without any limits, in the third case everything is completely deleted and just white background.
I have this ;(
click for check screen
How can I solve this problem? Help, good people)
Aleksandr Sevastyanov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.