在鼠标单击时在FigureCanvasQTAgg上绘制圆圈,需要以下步骤:
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtCore import Qt
class MyWindow(QMainWindow):
def __init__(self):
super().__init__()
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.setCentralWidget(self.canvas)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
x = event.pos().x()
y = event.pos().y()
self.draw_circle(x, y)
def draw_circle(self, x, y):
circle = plt.Circle((x, y), 10, color='r')
self.figure.gca().add_artist(circle)
self.canvas.draw()
if __name__ == '__main__':
app = QApplication([])
window = MyWindow()
window.show()
app.exec_()
通过以上步骤,在鼠标单击时,将在FigureCanvasQTAgg上绘制一个红色圆圈。可以根据实际需求调整圆圈的大小、颜色和其他属性。
参考链接:
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云