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

setTool

Sets the interactive tool currently being used on the canvas.

tool

Returns the currently active tool.

unsetTool

Unset the current tool.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsPlotCanvas. See the FAQ for more details.

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.

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.

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)

virtual 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:
virtual 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

virtual 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.

virtual refresh(self)[source]

Updates and redraws the plot.

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

virtual 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

virtual 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

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

virtual 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.

virtual zoomToRect(self, rect: QRectF)[source]

Zooms the plot to the specified rect in canvas units.

The default implementation does nothing.

Parameters:

rect (QRectF)