XyPlot (hwx.gui)#

class XyPlot(x=None, y=None, size=None, numberFormat='%g', zoomOnFit=1.2, **kwds)#

Bases: Frame

Creates a 2D plot.

Attribute Table#

Name

Type

bgColor

property

border

property

fontSize

property

footer

property

title

property

xlabel

property

xlimits

property

ylabel

property

ylimits

property

zeroLines

property

Method Table#

Name

Description

addCurve (self, y=[0], x=None, fit=True, **kwds)

Adds a curve to the plot.

addEventHandler (self, tool)

Adds a custom event handler to define the method associated to an event.

addXslider (self, x=0, **kwds)

Adds a movable vertical line to the plot.

addYslider (self, y=0, **kwds)

Adds a movable horizontal line to the plot.

clear (self)

Resets the title, x-y labels and footer and remove all curves,

ensureVisible (self, x=None, y=None, points=None)

Scales the axes so they contains the x, y and points.

fit (self, zoom=None, larger=False)

Rescales the axes so all curves are visible.

formatAxis (self, value, axis)

Called to format the x or y-axis major tick values.

formatHoverText (self, curve, x, y)

Called to format the curve point text when hovered.

formatNumber (self, value, format=None)

Formats the axis tick values using Inspire number formatting.

getDialogColor ()

getDialogTextColor ()

getPointUnderMouse (self, event, curves=None, tolerance=None)

Gets a CurvePoint under the mouse if a point could be found or None.

getSelectedPoints (self)

Returns all the selected points from plot.

getTheClosestPoint (self, x, y)

Gets the CurvePoint closest to specified x, y for all visible curves.

pan (self, dx, dy)

Translate the axes by the specified dx, dy.

redrawPlot (self, obj=None, name=None)

Refreshes the plot in gui idle.

selectPoints (self, points)

Selects the specified points in the plot.

setCursor (self, cursor, iconStrip=False, x=-1, y=-1)

Sets the mouse cursor at specified x, y location inside the plot.

setSnapping (self, on=True, xgrid=None, ygrid=None, snapPoints=None)

Snap mouse moves to points/lines as the user moves the mouse.

zoom (self, factor=1.5, point=None, axis=’both’)

Rescales the axes by the specified factor at the specified point.

zoomAtMouseEvent (self, event)

Rescales the axes by the specified points.

Example

from hwx import gui
from hwx.gui.XyPlot import XyPlot

# Constructor
plot = XyPlot(title="This is the plot Title
and Subtitle", size=(10, 10),
xlabel="X label", ylabel="Y label", footer="This is the plot footer")

# several properties that can be set
plot.xlimits = (-2.0, 2.0)
plot.ylimits = (-1.0, 3.0)
plot.bgColor = "lightblue"
plot.fontSize = 14
plot.border = 20
plot.numberFormat = "%g"
plot.zeroLines = True

show(plot)
property title#

Text on top of the plot.

property xlabel#

Text along the x-axis.

property ylabel#

Text along the y-axis.

property footer#

Text at the bottom of the figure.

property fontSize#

Size of the font in points.

property bgColor#

Specifies the background color of the plot.

property zeroLines#

Highlights the axes.

property border#

Size of the border around the plot.

property xlimits#

Min and max limits of the x-axis.

property ylimits#

Min and max limits of the y-axis.

addCurve(y=[0], x=None, fit=True, **kwds)#

Adds a curve to the plot.

In case x is None, it is set to x = list(range(len(y)))

Parameters:
  • y (list[float]) – The y values of the curve.

  • x (list[float]) – The x values of the curve.

  • fit (bool) – Determines if curve gets fitted inside the plot.

Returns:

The newly added Curve object.

Return type:

Curve

addXslider(x=0, **kwds)#

Adds a movable vertical line to the plot.

Parameters:

x (float) – The value where the slider will start from on the x-axis.

Returns:

The new added XSlider object.

Return type:

XSlider

addYslider(y=0, **kwds)#

Adds a movable horizontal line to the plot.

Parameters:

y (float) – The value where the slider will start from on the y-axis.

Returns:

The new added YSlider object.

Return type:

YSlider

clear()#

Resets the title, x-y labels and footer and remove all curves, sliders and tools, from the plot.

getTheClosestPoint(x, y)#

Gets the CurvePoint closest to specified x, y for all visible curves.

Parameters:
  • x (float) – The x value.

  • y (float) – The y value.

Returns:

The closet CurvePoint to the specified x, y values.

Return type:

CurvePoint

selectPoints(points)#

Selects the specified points in the plot.

Parameters:

points (list[Point]) – The list of points to be selected.

getSelectedPoints()#

Returns all the selected points from plot.

redrawPlot(obj=None, name=None)#

Refreshes the plot in gui idle.

fit(zoom=None, larger=False)#

Rescales the axes so all curves are visible.

Parameters:
  • zoom (float) – Padding scale factor around the curves.

  • larger (bool) – Determines if it will be fitted only in the case the computed scale exceeds the current.

Returns:

A reference to the instance XyPlot object on which it was called.

Return type:

XyPlot

zoom(factor=1.5, point=None, axis='both')#

Rescales the axes by the specified factor at the specified point.

Parameters:
  • factor (float) – The zoom factor. if factor > 1 the plot is zoomed out. If factor < 1 the plot is zoomed in.

  • point (Point) – Specified point to zoom into. Defaults to None, and the plot is scaled at the center.

  • axis (str) – The axis to be zoomed into. Defaults to “both”, valid choices are ‘x’ and ‘y’.

Returns:

A reference to the instance XyPlot object on which it was called.

Return type:

XyPlot

zoomAtMouseEvent(event)#

Rescales the axes by the specified points.

Parameters:

event (uiMouseEvent) – Mouse event to get start end end point of the window box select.

Returns:

A reference to the instance XyPlot object on which it was called.

Return type:

XyPlot

pan(dx, dy)#

Translate the axes by the specified dx, dy.

Parameters:
  • dx (float) – Differential x value to pan the x-axis by.

  • dy (float) – Differential y value to pan the y-axis by.

Returns:

A reference to the instance XyPlot object on which it was called.

Return type:

XyPlot

setCursor(cursor, iconStrip=False, x=-1, y=-1)#

Sets the mouse cursor at specified x, y location inside the plot.

Parameters:
  • cursor (str) – Cursor file name

  • iconStrip (bool) –

  • x (float) – The x location in the plot, to set the cursor at.

  • y (float) – The y location in the plot, to set the cursor at.

ensureVisible(x=None, y=None, points=None)#

Scales the axes so they contains the x, y and points.

Parameters:
  • x (float) – Specified x value.

  • y (float) – Specified y value.

  • points (Union[list[CurvePoints], str]) – Points to make visible. Points can be a list of CurvePoints of set to ‘selected’.

Returns:

A reference to the instance XyPlot object on which it was called.

Return type:

XyPlot

setSnapping(on=True, xgrid=None, ygrid=None, snapPoints=None)#

Snap mouse moves to points/lines as the user moves the mouse.

Parameters:
  • on (bool) – Determines the state of snapping.

  • xgrid (bool) – Determines whether it snaps to x-axis

  • ygrid (bool) – Determines whether it snaps to y-axis.

  • snapPoints (list[CurvePoints]) – The points/lines to snap to.

Returns:

A reference to the instance XyPlot object on which it was called.

Return type:

XyPlot

getPointUnderMouse(event, curves=None, tolerance=None)#

Gets a CurvePoint under the mouse if a point could be found or None.

Parameters:
  • event (MouseEvent) – The event to get the mouse cursor location.

  • curves (list[Curve]) – The curves to consider to get the point from. Defaults to None, considering all the curves in the plot.

  • tolerance (float) – The tolerance value to set the pick radius. Defaults to None, considering line maker radius only.

Returns:

The CurvePoint under the mouse.

Return type:

CurvePoint

addEventHandler(tool)#

Adds a custom event handler to define the method associated to an event.

If the action returns True, other event handlers for the same event will be blocked.

This is useful if you want to listen for a mouse release and get the plot value instead of the mouse x/y.

formatNumber(value, format=None)#

Formats the axis tick values using Inspire number formatting.

Parameters:
  • value (float) – The value to be formatted

  • format (str) – The format to be followed.

Returns:

formatted axis tick values.

Return type:

str

formatAxis(value, axis)#

Called to format the x or y-axis major tick values.

Parameters:
  • value (float) –

  • axis (str) – ‘x’ or ‘y’

Returns:

Value converted to a string

Return type:

str

formatHoverText(curve, x, y)#

Called to format the curve point text when hovered.

Parameters:
  • curve (Curve) –

  • x (float) – X value to be formatted.

  • y (float) – Y value to be formatted.

Returns:

The formatted string with X and Y value.

Return type:

str