本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.paintEvent方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.paintEvent方法的具体用法?Python FigureCanvasQTAgg.paintEvent怎么用?Python FigureCanvasQTAgg.paintEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
的用法示例。
在下文中一共展示了FigureCanvasQTAgg.paintEvent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import paintEvent [as 别名]
def paintEvent(self, event):
Canvas.paintEvent(self, event)
if not self.limit_mode:
return
# convert to data units
height = self.figure.bbox.height
t = lambda s: np.array(self.axes.transData.transform(s))
qp = QPainter()
qp.begin(self)
qp.setPen(QColor(*self.limit_color))
# Draw polygon
if self.limit_mode and self.limit_type == 1:
for i in range(len(self.limit_data) - 1):
start = t(self.limit_data[i])
end = t(self.limit_data[i + 1])
qp.drawLine(start[0], height - start[1],
end[0], height - end[1])
if self.limit_data:
start = t(self.limit_data[-1])
end = t((self._mouse_move_event.xdata,
self._mouse_move_event.ydata))
qp.drawLine(start[0], height - start[1],
end[0], height - end[1])
# Draw an ellipse
if self.limit_mode and self.limit_type == 2 and self.limit_data:
# convert to display coordinates
startp = t(self.limit_data[0])
mouse = t((self._mouse_move_event.xdata,
self._mouse_move_event.ydata))
center = 0.5 * (startp + mouse)
if len(self.limit_data) == 1: # we've set the center, draw line
eheight = 30
angvec = mouse - center
angle = np.arctan2(angvec[1], angvec[0])
ewidth = np.linalg.norm(angvec)
elif len(self.limit_data) > 1: # we've also fixed the angle
angleline = t(self.limit_data[1])
center = 0.5 * (startp + angleline)
angvec = angleline - center
angle = np.arctan2(angvec[1], angvec[0])
ewidth = np.linalg.norm(angvec)
angvec = angvec / ewidth
mvec = mouse - center
eheight = np.linalg.norm(mvec - np.dot(mvec, angvec) * angvec)
if self.limit_data:
qp.translate(center[0], height - center[1])
qp.rotate(-angle * 180.0 / np.pi)
qp.drawEllipse(QPoint(0, 0), ewidth, eheight)
qp.drawLine(-ewidth, 0, ewidth, 0)
qp.drawLine(0, -eheight, 0, eheight)
qp.end()
示例2: paintEvent
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import paintEvent [as 别名]
def paintEvent(self,e):
FigureCanvas.paintEvent(self,e)
if self._pressed:
painter = QPainter(self)
painter.setPen(QPen(Qt.DotLine))
(x1,y1) = self.figure.transFigure.inverted().transform([self._pressEvent.x,self._pressEvent.y])
(x2,y2) = self.figure.transFigure.inverted().transform([self._moveEvent.x,self._moveEvent.y])
painter.drawRect(x1*self.width(),(1-y1)*self.height(),(x2-x1)*self.width(),-(y2-y1)*self.height())
示例3: paintEvent
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import paintEvent [as 别名]
def paintEvent(self, event):
FigureCanvas.paintEvent(self,event)
painter = QtGui.QPainter()
painter.begin(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.fillRect(self.rect(), QtGui.QBrush(QtGui.QColor(255, 255, 255, 0)))
if self.counter<60:
painter.setPen(QtGui.QPen(Qt.NoPen))
for i in range(6):
if (old_div(self.counter, 5)) % 6 == i:
painter.setBrush(QtGui.QBrush(QtGui.QColor(127 + (self.counter % 5)*32, 127, 127)))
else:
painter.setBrush(QtGui.QBrush(QtGui.QColor(127, 127, 127)))
painter.drawEllipse(
old_div(self.width(),2) + 30 * math.cos(2 * math.pi * i / 6.0) - 10,
old_div(self.height(),2) + 30 * math.sin(2 * math.pi * i / 6.0) - 10,
20, 20)
painter.end()