Class: QgsPlotCanvas

class qgis.gui.QgsPlotCanvas

Bases: PyQt5.QtWidgets.QGraphicsView

Plot canvas is a class for displaying interactive 2d charts and plots.

Added in version 3.26.

QgsPlotCanvas(parent: Optional[QWidget] = None) Constructor for QgsPlotCanvas, with the specified parent widget.

Methods

actionEvent

centerPlotOn

Centers the plot on the plot point corresponding to x, y in canvas units.

changeEvent

childEvent

closeEvent

connectNotify

contextMenuEvent

create

crs

Returns the coordinate reference system (CRS) for map coordinates used by the canvas.

customEvent

destroy

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

drawBackground

drawForeground

drawFrame

dropEvent

enterEvent

event

param e:

eventFilter

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

hideEvent

initPainter

initStyleOption

inputMethodEvent

isSignalConnected

keyPressEvent

param e:

keyReleaseEvent

param e:

leaveEvent

metric

mouseDoubleClickEvent

param e:

mouseMoveEvent

param e:

mousePressEvent

param e:

mouseReleaseEvent

param e:

moveEvent

nativeEvent

paintEvent

panContentsBy

Pans the plot contents by dx, dy in canvas units.

receivers

refresh

Updates and redraws the plot.

resizeEvent

param e:

scalePlot

Scales the plot by a specified scale factor.

scrollContentsBy

sender

senderSignalIndex

setTool

Sets the interactive tool currently being used on the canvas.

setViewportMargins

setupViewport

sharedPainter

showEvent

snapToPlot

Snap a canvas point to the plot

tabletEvent

timerEvent

toCanvasCoordinates

Converts a point in map coordinates to the associated canvas point.

toMapCoordinates

Converts a point on the canvas to the associated map coordinate.

tool

Returns the currently active tool.

unsetTool

Unset the current tool.

updateMicroFocus

viewportEvent

param event:

viewportMargins

viewportSizeHint

wheelEvent

param e:

wheelZoom

Zoom plot from a mouse wheel event.

zoomToRect

Zooms the plot to the specified rect in canvas units.

Signals

contextMenuAboutToShow

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

plotAreaChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

toolChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

willBeDeleted

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

actionEvent(self, a0: QActionEvent | None)
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, a0: QEvent | None)
childEvent(self, a0: QChildEvent | None)
closeEvent(self, a0: QCloseEvent | None)
connectNotify(self, signal: QMetaMethod)
contextMenuAboutToShow

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

contextMenuEvent(self, event: QContextMenuEvent | None)
create(self, window: PyQt5.sip.voidptr = None, 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:

QgsCoordinateReferenceSystem

customEvent(self, a0: QEvent | None)
destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
disconnectNotify(self, signal: QMetaMethod)
dragEnterEvent(self, event: QDragEnterEvent | None)
dragLeaveEvent(self, event: QDragLeaveEvent | None)
dragMoveEvent(self, event: QDragMoveEvent | None)
drawBackground(self, painter: QPainter | None, rect: QRectF)
drawForeground(self, painter: QPainter | None, rect: QRectF)
drawFrame(self, a0: QPainter | None)
dropEvent(self, event: QDropEvent | None)
enterEvent(self, a0: QEvent | None)
event(self, e: QEvent | None) bool
Parameters:

e (Optional[QEvent])

Return type:

bool

eventFilter(self, a0: QObject | None, a1: QEvent | None) bool
focusInEvent(self, event: QFocusEvent | None)
focusNextChild(self) bool
focusNextPrevChild(self, next: bool) bool
focusOutEvent(self, event: QFocusEvent | None)
focusPreviousChild(self) bool
hideEvent(self, a0: QHideEvent | None)
initPainter(self, painter: QPainter | None)
initStyleOption(self, option: QStyleOptionFrame | None)
inputMethodEvent(self, event: QInputMethodEvent | None)
isSignalConnected(self, signal: QMetaMethod) bool
keyPressEvent(self, e: QKeyEvent | None)
Parameters:

e (Optional[QKeyEvent])

keyReleaseEvent(self, e: QKeyEvent | None)
Parameters:

e (Optional[QKeyEvent])

leaveEvent(self, a0: QEvent | None)
metric(self, a0: QPaintDevice.PaintDeviceMetric) int
mouseDoubleClickEvent(self, e: QMouseEvent | None)
Parameters:

e (Optional[QMouseEvent])

mouseMoveEvent(self, e: QMouseEvent | None)
Parameters:

e (Optional[QMouseEvent])

mousePressEvent(self, e: QMouseEvent | None)
Parameters:

e (Optional[QMouseEvent])

mouseReleaseEvent(self, e: QMouseEvent | None)
Parameters:

e (Optional[QMouseEvent])

moveEvent(self, a0: QMoveEvent | None)
nativeEvent(self, eventType: QByteArray | bytes | bytearray, message: PyQt5.sip.voidptr | None)
paintEvent(self, event: QPaintEvent | None)
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

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

receivers(self, signal: PYQT_SIGNAL) int
refresh(self)

Updates and redraws the plot.

resizeEvent(self, e: QResizeEvent | None)
Parameters:

e (Optional[QResizeEvent])

scalePlot(self, factor: float)

Scales the plot by a specified scale factor.

The default implementation does nothing.

Parameters:

factor (float)

scrollContentsBy(self, dx: int, dy: int)
sender(self) QObject | None
senderSignalIndex(self) int
setTool(self, tool: QgsPlotTool | None)

Sets the interactive tool currently being used on the canvas.

Parameters:

tool (Optional[QgsPlotTool])

setViewportMargins(self, left: int, top: int, right: int, bottom: int)
setViewportMargins(self, margins: QMargins) None
setupViewport(self, widget: QWidget | None)
sharedPainter(self) QPainter | None
showEvent(self, event: QShowEvent | None)
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:

QgsPointXY

tabletEvent(self, a0: QTabletEvent | None)
timerEvent(self, a0: QTimerEvent | None)
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:

QgsPointXY

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:

QgsPoint

tool(self) QgsPlotTool | None

Returns the currently active tool.

Return type:

Optional[QgsPlotTool]

toolChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

unsetTool(self, tool: QgsPlotTool | None)

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 (Optional[QgsPlotTool])

updateMicroFocus(self)
viewportEvent(self, event: QEvent | None) bool
Parameters:

event (Optional[QEvent])

Return type:

bool

viewportMargins(self) QMargins
viewportSizeHint(self) QSize
wheelEvent(self, e: QWheelEvent | None)
Parameters:

e (Optional[QWheelEvent])

wheelZoom(self, event: QWheelEvent | None)

Zoom plot from a mouse wheel event.

The default implementation does nothing.

Parameters:

event (Optional[QWheelEvent])

willBeDeleted

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

zoomToRect(self, rect: QRectF)

Zooms the plot to the specified rect in canvas units.

The default implementation does nothing.

Parameters:

rect (QRectF)