Plot Widget#

class squap.widgets.plot_widget.SubplotWidget(row, col, **kwargs)[source]#

All plotting functions are methods of this widget. e.g. squap.plot() actually redirects to SubplotWidget.plot of the main SubplotWidget. When subplots are created with squap.subplots() you get an axs list which contains the created SubplotWidget, so that e.g. axs[0].plot will create a regular plot in the first SubplotWidget.

plot(
*args,
color='y',
width=1,
dashed=False,
dash_pattern=None,
connect='auto',
gradient=None,
line_style=None,
antialias=True,
auto_downsample=False,
downsample=1,
downsample_method='mean',
skip_finite_check=False,
**kwargs,
)[source]#

Creates a new plot curve, and calls set_data with the other (keyword) arguments.

Parameters:
  • *args – Provide x and y, just y, or no data at all. Data can also be passed as keyword arguments.

  • color (ColorsType) – The color of the line. Default is "y" (yellow). Can also be a gradient (created with squap.get_gradient()).

  • width (int) – Width of the plot line. Default is 1.

  • dashed (bool) – If True, draws a dashed line between the points (for more options see dash_pattern). Default is False.

  • dash_pattern (list, optional) – How the dashes are spaced. For example, if dash_pattern is [16, 16, 4, 16], the pattern will be: one dash of 16 pixels long, then a space of 16 pixels long, then a dash of 4 pixels long and then a dash of 16 pixels long. This pattern is then repeated. This should be a list with a length that is an integer multiple of 2. Setting dash_pattern will also automatically set dashed to True. Defaults to [16, 16].

  • connect (str or np.ndarray) –

    Can be one of the following options:

    • "all": Connects all points.

    • "pairs": Generates lines between every other point.

    • "finite": Creates a break when a nonfinite points is encountered.

    • "auto": This will normally use "all", but if any nonfinite data points are detected, it will automatically switch to "finite".

    • ndarray - N values of 0 or 1 (N being the length of x and y). Values of 1 indicate that the respective point will be connected to the next.

    Defaults to "auto".

  • gradient (QGradient, optional) – gradient of the line. Use squap.get_gradient() to get the gradient. The gradient can be seen as a 2D image of a gradient which appears at each pixel that lies on the line. When style of the gradient is set to "horizontal" or "vertical", or "radial" without providing position, the bounds of the gradient will be automatically determined when set_data is called, which can decrease performance. So, specify position for optimal performance. Default is None.

  • line_style (optional, str) – todo: some presets for simplicity, ls is also allowed instead of line_style.

  • downsample (int) – Reduce the number of samples displayed by the given factor. Default is 1 (no downsampling).

  • downsample_method (str) –

    Can be one of the following options:

    • "subsample": Downsample by taking the first of downsample samples. This method is fastest and least accurate. Length of datasets will be divided by downsample

    • "mean": Downsample by taking the mean of downsample samples. Length of datasets will be divided by downsample.

    • "peak": Downsample by drawing a saw wave that follows the min and max of the original data. This method produces the best visual representation of the data but is slower. Length of dataset will stay the same.

    Defaults to "mean".

  • auto_downsample (bool) – Can increase performance by not drawing one pixel multiple times, but is slower for less data. Defaults to False.

  • antialias (bool) – Antialiasing can be disabled for a minor performance increase. Default is True.

  • skip_finite_check (bool) – Optimization flag that can speed up plotting by not checking and compensating for NaN values. If set to True, and NaN values exist, unpredictable behavior will occur. The data may not be displayed or the plot may take a significant performance hit. Defaults to False.

  • **kwargs – Can contain aliases and the following: - x: You can provide x as keyword argument as well. - y: You can provide y as keyword argument as well.

Returns:

The generated curve.

Return type:

PlotCurve

scatter(
*args,
color='y',
size=7,
edge_width=-1,
edge_color='white',
pixel_mode=True,
downsample=1,
downsample_method='mean',
auto_downsample=False,
antialias=True,
**kwargs,
)[source]#

Creates a new scatter curve, and calls set_data with the other arguments. If both x and y are provided, you can set them together using scatter(x, y, ...). If only y is provided using scatter(y, ...), x is set as the index of y. x and y can also be passed as keyword arguments by doing scatter(x=x, ...), scatter(y=y) or scatter(x=x, y=y, ...). Furthermore, you can include additional keyword arguments such as color and size to customize the appearance of the curve.

Parameters:
  • *args – Provide x and y, just y, or no data at all. Data can also be passed as keyword arguments.

  • color (ColorType) – the color of the points. See ColorsType for allowed values. If a list of colors is passed, it should be the same length as x and y.

  • size (int or list of int) – The size of the scatter plot points. Also accepted as s. Default is 7.

  • edge_width (int or list of int) – Width of the edge around each point. Default is -1 (no edge).

  • edge_color (ColorsType) – Color of the edge around each point. Default is white.

  • pixel_mode (bool) – Whether to fix the size of each point. If True, size is specified in pixels. If False, size is specified in data coordinates. Defaults to True.

  • downsample (int) – Reduce the number of samples displayed by the given factor. Default is 1 (no downsampling).

  • downsample_method (str) –

    Can be one of the following options:

    • "subsample": Downsample by taking the first of downsample samples. This method is fastest and least accurate. Length of datasets will be divided by downsample

    • "mean": Downsample by taking the mean of downsample samples. Length of datasets will be divided by downsample.

    • "peak": Downsample by drawing a saw wave that follows the min and max of the original data. This method produces the best visual representation of the data but is slower. Length of dataset will stay the same.

    Defaults to "mean".

  • auto_downsample (bool) – Can increase performance by not drawing one pixel multiple times, but is slower for less data. Defaults to False.

  • antialias (bool) – Antialiasing can be disabled for a minor performance increase. Default is True.

  • kwargs – Can contain the following: - x: You can provide x as keyword argument as well. - y: You can provide y as keyword argument as well.

Returns:

The generated curve.

Return type:

PlotCurve

errorbar(
*args,
x_err=None,
y_err=None,
color='y',
width=1,
errorbar_width=1,
beam_size=0,
dashed=False,
dash_pattern=None,
connect='auto',
gradient=None,
line_style=None,
antialias=True,
auto_downsample=False,
downsample=1,
downsample_method='mean',
skip_finite_check=False,
**kwargs,
)[source]#

Creates a new errorbar curve, and calls set_data with the other (keyword) arguments.

Parameters:
  • *args – For providing x and y. (Can also be provided as keyword arguments). x and y must be the same length. If only one argument is provided, it is interpreted as y and x is set to the index of y.

  • x_err

    Size of the errorbar at each x value. Can be the following types:

    • None: No error in the x-direction.

    • float: x-error at all points.

    • Iterable of same size as x: x-error at each point.

    • Iterable of size (Nx, 2): x_err[i, 0] is the error on the left at each point, and x_err[i, 1] is the error on the right at each point i.

    Defaults to None.

  • y_err – Same as x_err but for y.

  • color (ColorType) – Color of the line and errorbars. Default is "y" (yellow). Can also be a gradient (see squap.get_gradient()). If the color of the line and of the errorbar should be different, provide both line_color and errorbar_color.

  • width (int) – Width of the plot line. Default is 1. Does not affect the width of the errorbars.

  • errorbar_width (int) – Width of the errorbar lines. Default is 1.

  • beam_size (float) – Size of the bars at the ends of the errorbar lines. Default is 0.

  • dashed (bool) – If True, draws a dashed line between the points (for more options see dash_pattern). Defaults to False.

  • dash_pattern (list, optional) – How the dashes are spaced. For example, if dash_pattern is [16, 16, 4, 16], the pattern will be: one dash of 16 pixels long, then a space of 16 pixels long, then a dash of 4 pixels long and then a dash of 16 pixels long. This pattern is then repeated. This should be a list with a length that is an integer multiple of 2. Setting dash_pattern will also automatically set dashed to True. Defaults to [16, 16].

  • connect (str or np.ndarray) –

    Can be one of the following options:

    • "all": Connects all points.

    • "pairs": Generates lines between every other point.

    • "finite": Creates a break when a nonfinite points is encountered.

    • "auto": This will normally use "all", but if any nonfinite data points are detected, it will automatically switch to "finite".

    • ndarray - N values of 0 or 1 (N being the length of x and y). Values of 1 indicate that the respective point will be connected to the next.

    Defaults to "auto".

  • line_style (str, optional) – todo: some presets for simplicity, ls is also allowed instead of line_style.

  • gradient (QGradient, optional) – gradient of the line. Use squap.get_gradient() to get the gradient. The gradient can be seen as a 2D image of a gradient which appears at each pixel that lies on the line. When style of the gradient is set to "horizontal" or "vertical", or "radial" without providing position, the bounds of the gradient will be automatically determined when set_data is called, which can decrease performance. So, specify position for optimal performance.

  • downsample (int) – Reduce the number of samples displayed by the given factor. Default is 1 (no downsampling).

  • downsample_method (str) –

    Can be one of the following options:

    • "subsample": Downsample by taking the first of downsample samples. This method is fastest and least accurate. Length of datasets will be divided by downsample

    • "mean": Downsample by taking the mean of downsample samples. Length of datasets will be divided by downsample.

    • "peak": Downsample by drawing a saw wave that follows the min and max of the original data. This method produces the best visual representation of the data but is slower. Length of dataset will stay the same.

    Defaults to "mean".

  • auto_downsample (bool) – Can increase performance by not drawing one pixel multiple times, but is slower for less data. Defaults to False.

  • antialias (bool) – Antialiasing can be disabled for a minor performance increase. Default is True.

  • skip_finite_check (bool) – Optimization flag that can speed up plotting by not checking and compensating for NaN values. If set to True, and NaN values exist, unpredictable behavior will occur. The data may not be displayed or the plot may take a significant performance hit. Defaults to False.

  • **kwargs – Can contain the following: - x: You can provide x as keyword argument as well. - y: You can provide y as keyword argument as well. - line_color: For seperating errorbar and line color. - error_color: For seperating errorbar and line color. - line_width: For seperating errorbar and line width. - error_width: For seperating errorbar and line width.

Returns:

The generated curve. The errorbar curve is technically located at ErrorbarCurve, but everything can be set with just PlotCurve.set_data().

Return type:

PlotCurve

inf_dline(
pos,
angle=45,
color='y',
width=1,
dashed=False,
dash_pattern=None,
line_style=None,
movable=False,
bounds=None,
span=(0, 1),
line_movable=None,
label=False,
label_text='{value}',
label_movable=None,
label_position=0.5,
label_anchors=None,
hover_color='red',
hover_width=1,
name=None,
**kwargs,
)[source]#

Creates an infinite line with any orientation and add it to the view.

Parameters:
  • pos (float or tuple) – A position through which the line runs. When angle is 0 or 90 this can be a single value: the y- or x-value of the line respectively.

  • angle (float) – The angle of the line in degrees. 0 is horizontal, 90 is vertical. Default is 45.

  • color (ColorType) – Color of the line. Default is "y" (yellow). Can also be a gradient.

  • width (int) – Width of the plot line. Default is 1.

  • dashed (bool) – If True, draws a dashed line between the points (for more options see dash_pattern). Default is False.

  • dash_pattern (list, optional) – How the dashes are spaced. For example, if dash_pattern is [16, 16, 4, 16], the pattern will be: one dash of 16 pixels long, then a space of 16 pixels long, then a dash of 4 pixels long and then a dash of 16 pixels long. This pattern is then repeated. This should be a list with a length that is an integer multiple of 2. Setting dash_pattern will also automatically set dashed to True. Defaults to [16, 16].

  • line_style (str) – todo: some presets for simplicity, ls is also allowed instead of line_style.

  • movable (bool, optional) – Whether the line (and label if it exists) is movable or not. Default is False.

  • bounds (tuple, optional) – Optional (min, max) bounding values. Bounds are only valid if the line is vertical or horizontal. Default is no bounds.

  • span (tuple) – The length of the line on screen. The first number is how far it extends to todo: complete

  • line_movable (bool, optional) – Whether the line is movable or not. Overwrites movable if changed. Default is None.

  • label (bool) – The label doesn’t work completely yet, I think this is due to pyqtgraph itself. Will look into this later. If True, a label is added to the line. Default is False.

  • label_text (str) – The text that is shown on the label. {value} can be used inside the string, which will be replaced by the lines current position. Default is "{value}".

  • label_movable (bool, optional) – Whether the label is movable or not. Overwrites movable if changed. Default is None.

  • label_position (float) – The relative position (between 0.0 and 1.0) of this label within the view box and along the line. Default is 0.5, meaning in the middle.

  • label_anchors (list, optional) – todo: write

  • hover_color (ColorType) – Color to use when the mouse cursor hovers over the line. Only used when movable=True. Default is red.

  • hover_width (int) – Width to use when the mouse cursor hovers over the line. Default is 1.

  • name (str, optional) – Name of the item (for the legend).

  • **kwargs – Some aliases are allowed.

Returns:

The generated line.

Return type:

InfLine

inf_hline(
pos,
color='y',
width=1,
dashed=False,
dash_pattern=None,
line_style=None,
movable=False,
bounds=None,
span=(0, 1),
line_movable=None,
label=False,
label_text='{value}',
label_movable=None,
label_position=0.5,
label_anchors=None,
hover_color='red',
hover_width=1,
name=None,
**kwargs,
)[source]#

This function is used to create a horizontal infinite line and add it to the view. This function is the same as inf_dline(pos, angle=90, ...) but instead the default label_text is now "y={value}".

inf_vline(
pos,
color='y',
width=1,
dashed=False,
dash_pattern=None,
line_style=None,
movable=False,
bounds=None,
span=(0, 1),
line_movable=None,
label=False,
label_text='{value}',
label_movable=None,
label_position=0.5,
label_anchors=None,
hover_color='red',
hover_width=1,
name=None,
**kwargs,
)[source]#

This function is used to create a horizontal infinite line and add it to the view. This function is the same as inf_dline(pos, angle=90, ...) but instead the default label_text is now "x={value}".

grid(
tick_spacing=None,
color=None,
width=1,
**kwargs,
)[source]#

This function is used to create a grid and add it to view. Todo: improve Use squap.show_grid() for simple use-cases.

Parameters:
  • tick_spacing (tuple or float, optional) – Set the grid spacing. When set to None grid line distance is chosen automatically. When an iterable is given, give x- and y-spacing. When 1 value is given, this value is used for both x and y. For more complex scaling you can set the x- and y-spacing on different scales. Eg. passing ([1, 100], None) will mean x-spacing is automatically determined to be either 1 or 100, and y-spacing is completely automatic. Replacing [1, 100] by [1, 100, None] will mean it can be 1 or 100 depending on zoom level, or it can be completely automatic for anything outside this range.

  • color (ColorType, optional) – Color of the lines. Defaults to the config foreground color.

  • width (int) – Width of the plot line. Default is 1.

  • **kwargs – Some aliases are allowed.

Returns:

The generated grid.

Return type:

GridCurve

plot_text(
text,
pos,
color=(0.8, 0.8, 0.8),
angle=0,
font=None,
font_size=None,
html=None,
text_width=None,
**kwargs,
)[source]#

Displays a text object at coordinates pos. See squap.get_font() for more information on fonts.

Parameters:
  • text (str) – The text to be displayed.

  • pos (tuple) – The position of the text in coordinates on the 2D plane.

  • color (ColorType, optional) – Color of the text. Defaults to gray.

  • angle (float, optional) – Angle at which the text is placed in degrees. Defaults to 0.

  • font (str or Font, optional) – The font of the text. Defaults to Segoe UI.

  • font_size (int, optional) – if set to 0 or negative, system default fontsize is used (usually 12)

  • html (str, optional) – The html to display, overwrites all other font arguments. Defaults to None.

  • text_width (int, optional) – The width of the text. Todo: check how it works

Returns:

The created text object.

Return type:

TextCurve

imshow(
data=None,
location=None,
cmap=None,
auto_levels=False,
levels=None,
axis_order='row-major',
border_color=None,
**kwargs,
)[source]#

Creates an image at location location. This image consists of equally spaced pixels, colored according to data and cmap. This function hasn’t been tested thoroughly

Parameters:
  • data (np.ndarray, optional) –

    Array containing data to be shown. Can be shape:

    • (Nx, Ny, 3): array of colors, between 0 and 1.

    • (Nx, Ny, 4): array of colors, between 0 and 1, with alpha values.

    • (Nx, Ny): array of values between 0 and 1, corresponding to grayscale or colors corresponding to cmap if it is provided.

  • location (tuple, optional) – Location of the image. (location[0], location[1]) is the bottom left coordinate, and (location[2], location[3]) is the top right coordinate.

  • cmap (Any) – Colormap from squap.get_cmap() or data argument accepted by squap.get_cmap().

  • auto_levels (bool, optional) – todo: describe

  • levels (optional) – todo: describe

  • axis_order (bool, optional) – Whether the ordering of the pixels listed in data is "row-major" or "col-major". Todo: test if it does anything.

  • border_color (ColorType, optional) – Color of the border around the image. Defaults to None, meaning no border.

  • todo – border thickness?

Returns:

The created image curve.

Return type:

ImageCurve

lock_zoom(curves)[source]#

Locks zoom onto current range of specified curves. Works only if they are normal curves with x- and y- data.

Parameters:

curves (list of curves) – curves on which the zoom should lock

set_xlim(x_min, x_max)[source]#

Sets the view range in the x direction.

Parameters:
  • x_min (float) – minimum x value for the plot range

  • x_max (float) – maximum x value for the plot range

set_ylim(y_min, y_max)[source]#

Sets the view range in the x direction.

Parameters:
  • y_min (float) – minimum y value for the plot range

  • y_max (float) – maximum y value for the plot range

xlim()[source]#

Returns current xlim.

Return type:

tuple[float]

ylim()[source]#

” Returns current ylim.

Return type:

tuple[float]

disable_flicker(
disable=True,
)[source]#

This function can be called to disable the flickering that sometimes occur with fast updating plots. It does slow down plotting.