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 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, 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

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, QContextMenuEvent)
create(self, window: PyQt5.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

QgsCoordinateReferenceSystem

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], PyQt5.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

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, 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)
sharedPainter(self) QPainter
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

QgsPointXY

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

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

Returns the currently active tool.

Return type

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)

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

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) –