PyQt5-底图和Matplotlib散点图选择器

时间:2018-08-12 18:30:12

标签: python pyqt5 matplotlib-basemap

我在Basemap上绘制了点,现在我尝试添加一个拾取事件。使用qwidget将地图嵌入到PyQt5中。 基于此documentation,我尝试了以下代码:

self.axes.figure.canvas.mpl_connect(self, 'pick_event', self.onclick)

但是我得到这个错误:

TypeError: mpl_connect() takes 3 positional arguments but 4 were given

这是我的代码:

from PyQt5 import QtCore, QtGui, QtWidgets
from mpl_toolkits.basemap import Basemap
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton
from Front_end import Ui_MainWindow
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 os

class Ui_MainWindow(QMainWindow, Ui_MainWindow):

    def __init__(self, parent=None):
        super(Ui_MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.graph1 = MyCanvas()
        self.navi_toolbar = NavigationToolbar(self.graph1, self) 
        self.gridLayout_2.addWidget(self.navi_toolbar, 1, 0, 1, 1)
        self.gridLayout_2.addWidget(self.graph1, 0, 0, 1, 1) 
        self.plot_point()

    def onclick(self, event):
        print('test')

    def plot_point(self):        
        self.graph1.figure.clf()
        self.axes = self.graph1.figure.add_subplot(111)
        self.x = [0, 10, 20, 30]
        self.y = [0, 10, 20, 30]
        self.map = Basemap(resolution = 'l')
        self.map.drawmapboundary(fill_color='#00BFFF',zorder=1)
        self.map.fillcontinents(color='#F5D0A9',zorder=2,lake_color='aqua')         
        self.axes.scatter(self.y,self.x, color='#FF0080', s=75, marker="*", zorder=4)
        self.axes.figure.canvas.mpl_connect(self, 'pick_event', self.onclick) 

class MyCanvas(FigureCanvas): 

    def __init__(self, *args, **kwargs):
        self.figure = plt.figure()
        FigureCanvas.__init__(self, self.figure)
        self.figure.patch.set_facecolor("None")
        self.figure.subplots_adjust(left=0.019, bottom=0.035, right=0.99, top=0.964)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    prog = Ui_MainWindow()    
    prog.showMaximized()
    sys.exit(app.exec_())

0 个答案:

没有答案