Class: QgsPlotCanvas

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

Added in version 3.26.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsPlotCanvas

Base classes

QGraphicsView

QAbstractScrollArea

QFrame

QWidget

QObject

QPaintDevice

Subclasses

QgsElevationProfileCanvas

A canvas for elevation profiles.

Methods

centerPlotOn

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

crs

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

panContentsBy

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

refresh

Updates and redraws the plot.

scalePlot

Scales the plot by a specified scale factor.

setTool

Sets the interactive tool currently being used on the canvas.

snapToPlot

Snap a canvas point to the plot

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.

wheelZoom

Zoom plot from a mouse wheel event.

zoomToRect

Zooms the plot to the specified rect in canvas units.

Signals

contextMenuAboutToShow

Emitted before the canvas context menu will be shown.

plotAreaChanged

Emitted whenever the visible area of the plot is changed.

toolChanged

Emitted when the plot tool is changed.

willBeDeleted

Emitted in the destructor when the canvas is about to be deleted, but is still in a perfectly valid state.

class qgis.gui.QgsPlotCanvas[source]

Bases: QGraphicsView

__init__(parent: QWidget | None = None)

Constructor for QgsPlotCanvas, with the specified parent widget.

Parameters:

parent (Optional[QWidget] = None)

centerPlotOn(self, x: float, y: float)[source]

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

The default implementation does nothing.

Parameters:
  • x (float)

  • y (float)

signal contextMenuAboutToShow(menu: QMenu, event: QgsPlotMouseEvent)[source]

Emitted before the canvas context menu will be shown. Can be used to extend the context menu.

Parameters:
crs(self) QgsCoordinateReferenceSystem[source]

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

panContentsBy(self, dx: float, dy: float)[source]

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

The default implementation does nothing.

Parameters:
  • dx (float)

  • dy (float)

signal plotAreaChanged[source]

Emitted whenever the visible area of the plot is changed.

refresh(self)[source]

Updates and redraws the plot.

scalePlot(self, factor: float)[source]

Scales the plot by a specified scale factor.

The default implementation does nothing.

Parameters:

factor (float)

setTool(self, tool: QgsPlotTool | None)[source]

Sets the interactive tool currently being used on the canvas.

Parameters:

tool (Optional[QgsPlotTool])

snapToPlot(self, point: QPoint) QgsPointXY[source]

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

toCanvasCoordinates(self, point: QgsPoint) QgsPointXY[source]

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[source]

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[source]

Returns the currently active tool.

Return type:

Optional[QgsPlotTool]

signal toolChanged(newTool: QgsPlotTool)[source]

Emitted when the plot tool is changed.

Parameters:

newTool (QgsPlotTool)

unsetTool(self, tool: QgsPlotTool | None)[source]

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

wheelZoom(self, event: QWheelEvent | None)[source]

Zoom plot from a mouse wheel event.

The default implementation does nothing.

Parameters:

event (Optional[QWheelEvent])

signal willBeDeleted[source]

Emitted in the destructor when the canvas is about to be deleted, but is still in a perfectly valid state.

zoomToRect(self, rect: QRectF)[source]

Zooms the plot to the specified rect in canvas units.

The default implementation does nothing.

Parameters:

rect (QRectF)