Saya punya masalah dengan python 2.7. Pertanyaan: Ketika saya menggunakan fungsi zoom, saya tidak dapat menggunakan "keyboard" untuk mencetak data asli saya. Di sini, saya menambahkan acara keyboard dalam kode saya. Bagaimana saya ada di kedua fungsi? Bagaimana saya harus men-debug kode?

 import matplotlib
    import sys
    import random
    matplotlib.use("Qt5Agg")
    from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
    from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
    from matplotlib.figure import Figure
    import matplotlib.pyplot as plt
    import numpy as np 
    from PyQt5.QtCore import *
    import re
    
    class MyMplCanvas(FigureCanvas):
        def __init__(self, parent=None, width=10, height=4, dpi=100):
            FigureCanvas.__init__(self, Figure(figsize=(width, height), dpi=dpi))
            self.setParent(parent)
            FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
            FigureCanvas.updateGeometry(self)
            self.axes = self.figure.add_subplot(211)
            self.mpl_connect("motion_notify_event", self.on_move)
            self.po_annotation = []
            self.ff=[]
        def start_static_plot(self):
            for i in range(0, 990):
                (point,) = self.axes.plot(x, y, "-o")
                annotation = self.axes.annotate(
                    ("x=" + str(x), "y=" + str(y)),
                    textcoords="data",
                    horizontalalignment="left",
         arrowprops=dict(arrowstyle="simple",connectionstyle="arc3,rad=+0.2"),                    bbox=dict(boxstyle="round", facecolor="w", edgecolor="0.1", alpha=0.9)
                annotation.set_visible(False)
                self.po_annotation.append([point, annotation])
            self.axes.set_xlim(-0.5, 1000)
            self.axes.set_ylim(-5, 9.5 ** 2)  
        def on_move(self, event):
            visibility_changed = Ture
            for point, annotation in self.po_annotation:
                should_be_visible = point.contains(event)[4]
                if should_be_visible != annotation.get_visible():
                    visibility_changed = True
                    annotation.set_visible(should_be_visible)
                    datachouse=str(annotation)
                    self.ff = np.loadtxt(f)
            if visibility_changed:
                self.draw()                
          def mouseReleaseEvent(self, event):
                if(event.button() == Qt.LeftButton):    
        def initUi(self):
            self.mpl.start_static_plot()
            self.layout.addWidget(self.mpl)
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        sys.exit(app.exec_()) 
0
user13635794 3 Juli 2020, 07:10

1 menjawab

Jika Anda tidak ingin menghapus perilaku default suatu metode, maka Anda harus memanggil metode induk:

def mouseReleaseEvent(self, event):
    super(MyMplCanvas, self).mouseReleaseEvent(event)
    if event.button() == Qt.LeftButton:
        print("result=", self.ff)
0
eyllanesc 3 Juli 2020, 04:21