Class: QgsPlotCanvas¶
- class qgis.gui.QgsPlotCanvas¶
Bases:
PyQt5.QtWidgets.QGraphicsView
Plot canvas is a class for displaying interactive 2d charts and plots.
New in version 3.26.
QgsPlotCanvas(parent: QWidget = None) Constructor for
QgsPlotCanvas
, with the specifiedparent
widget.Methods
Centers the plot on the plot point corresponding to
x
,y
in canvas units.Returns the coordinate reference system (CRS) for map coordinates used by the canvas.
- param e
- param e
- param e
- param e
- param e
- param e
- param e
Pans the plot contents by
dx
,dy
in canvas units.Updates and redraws the plot.
- param e
Scales the plot by a specified
scale
factor.scrollContentsBy
Sets the interactive tool currently being used on the canvas.
Snap a canvas point to the plot
Converts a
point
in map coordinates to the associated canvas point.Converts a
point
on the canvas to the associated map coordinate.Returns the currently active tool.
Unset the current
tool
.- param event
- param e
Zoom plot from a mouse wheel
event
.Zooms the plot to the specified
rect
in canvas units.Signals
Emitted before the canvas context menu will be shown.
Emitted whenever the visible area of the plot is changed.
Emitted when the plot tool is changed.
Emitted in the destructor when the canvas is about to be deleted, but is still in a perfectly valid state.
- actionEvent(self, QActionEvent)¶
- centerPlotOn(self, x: float, y: float)¶
Centers the plot on the plot point corresponding to
x
,y
in canvas units.The default implementation does nothing.
- Parameters
x (float) –
y (float) –
- changeEvent(self, QEvent)¶
- childEvent(self, QChildEvent)¶
- closeEvent(self, QCloseEvent)¶
- connectNotify(self, QMetaMethod)¶
- contextMenuAboutToShow¶
Emitted before the canvas context menu will be shown. Can be used to extend the context menu. [signal]
- Parameters
menu (QMenu) –
event (QgsPlotMouseEvent) –
- contextMenuEvent(self, QContextMenuEvent)¶
- create(self, window: sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)¶
- crs(self) QgsCoordinateReferenceSystem ¶
Returns the coordinate reference system (CRS) for map coordinates used by the canvas.
May return an invalid CRS if no CRS is associated with the canvas.
- Return type
- customEvent(self, QEvent)¶
- destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)¶
- disconnectNotify(self, QMetaMethod)¶
- dragEnterEvent(self, QDragEnterEvent)¶
- dragLeaveEvent(self, QDragLeaveEvent)¶
- dragMoveEvent(self, QDragMoveEvent)¶
- drawBackground(self, QPainter, QRectF)¶
- drawForeground(self, QPainter, QRectF)¶
- drawFrame(self, QPainter)¶
- dropEvent(self, QDropEvent)¶
- enterEvent(self, QEvent)¶
- event(self, e: QEvent) bool ¶
- Parameters
e (QEvent) –
- Return type
bool
- eventFilter(self, QObject, QEvent) bool ¶
- focusInEvent(self, QFocusEvent)¶
- focusNextChild(self) bool ¶
- focusNextPrevChild(self, bool) bool ¶
- focusOutEvent(self, QFocusEvent)¶
- focusPreviousChild(self) bool ¶
- hideEvent(self, QHideEvent)¶
- initPainter(self, QPainter)¶
- initStyleOption(self, QStyleOptionFrame)¶
- inputMethodEvent(self, QInputMethodEvent)¶
- isSignalConnected(self, QMetaMethod) bool ¶
- keyPressEvent(self, e: QKeyEvent)¶
- Parameters
e (QKeyEvent) –
- keyReleaseEvent(self, e: QKeyEvent)¶
- Parameters
e (QKeyEvent) –
- leaveEvent(self, QEvent)¶
- metric(self, QPaintDevice.PaintDeviceMetric) int ¶
- mouseDoubleClickEvent(self, e: QMouseEvent)¶
- Parameters
e (QMouseEvent) –
- mouseMoveEvent(self, e: QMouseEvent)¶
- Parameters
e (QMouseEvent) –
- mousePressEvent(self, e: QMouseEvent)¶
- Parameters
e (QMouseEvent) –
- mouseReleaseEvent(self, e: QMouseEvent)¶
- Parameters
e (QMouseEvent) –
- moveEvent(self, QMoveEvent)¶
- nativeEvent(self, Union[QByteArray, bytes, bytearray], sip.voidptr) Tuple[bool, int] ¶
- paintEvent(self, QPaintEvent)¶
- panContentsBy(self, dx: float, dy: float)¶
Pans the plot contents by
dx
,dy
in canvas units.The default implementation does nothing.
- Parameters
dx (float) –
dy (float) –
- plotAreaChanged¶
Emitted whenever the visible area of the plot is changed. [signal]
- receivers(self, PYQT_SIGNAL) int ¶
- refresh(self)¶
Updates and redraws the plot.
- resizeEvent(self, e: QResizeEvent)¶
- Parameters
e (QResizeEvent) –
- scalePlot(self, factor: float)¶
Scales the plot by a specified
scale
factor.The default implementation does nothing.
- Parameters
factor (float) –
- QgsPlotCanvas.scrollContentsBy(self, int, int)
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setTool(self, tool: QgsPlotTool)¶
Sets the interactive tool currently being used on the canvas.
- Parameters
tool (QgsPlotTool) –
- QgsPlotCanvas.setViewportMargins(self, int, int, int, int)
- setViewportMargins(self, QMargins) None ¶
- setupViewport(self, QWidget)¶
- showEvent(self, QShowEvent)¶
- snapToPlot(self, point: QPoint) QgsPointXY ¶
Snap a canvas point to the plot
Returns an empty point if snapping was not possible.
- Parameters
point (QPoint) – point in canvas coordinates
- Return type
- tabletEvent(self, QTabletEvent)¶
- timerEvent(self, QTimerEvent)¶
- toCanvasCoordinates(self, point: QgsPoint) QgsPointXY ¶
Converts a
point
in map coordinates to the associated canvas point.May return an empty point if the map point cannot be converted to a canvas point.
- Parameters
point (QgsPoint) –
- Return type
- toMapCoordinates(self, point: QgsPointXY) QgsPoint ¶
Converts a
point
on the canvas to the associated map coordinate.May return an empty point if the canvas point cannot be converted to a map point.
- Parameters
point (QgsPointXY) –
- Return type
- tool(self) QgsPlotTool ¶
Returns the currently active tool.
- Return type
- toolChanged¶
Emitted when the plot tool is changed. [signal]
- Parameters
newTool (QgsPlotTool) –
- unsetTool(self, tool: QgsPlotTool)¶
Unset the current
tool
.This is called from destructor of plot tools to make sure that this map tool won’t be used any more.
You don’t have to call it manually,
QgsPlotTool
takes care of it.- Parameters
tool (QgsPlotTool) –
- updateMicroFocus(self)¶
- viewportEvent(self, event: QEvent) bool ¶
- Parameters
event (QEvent) –
- Return type
bool
- viewportMargins(self) QMargins ¶
- viewportSizeHint(self) QSize ¶
- wheelEvent(self, e: QWheelEvent)¶
- Parameters
e (QWheelEvent) –
- wheelZoom(self, event: QWheelEvent)¶
Zoom plot from a mouse wheel
event
.The default implementation does nothing.
- Parameters
event (QWheelEvent) –
- willBeDeleted¶
Emitted in the destructor when the canvas is about to be deleted, but is still in a perfectly valid state. [signal]
- zoomToRect(self, rect: QRectF)¶
Zooms the plot to the specified
rect
in canvas units.The default implementation does nothing.
- Parameters
rect (QRectF) –