Skip to content

API Figure

Emil Wagman edited this page Nov 27, 2023 · 7 revisions

Figure()

A Python class for plotting numerical data into graphical figures.

Attributes:

  • figsize (tuple[int, int]): Sets the output size of the figure.

Example usage:

import numpy as np
import wplt

X = np.linspace(0, 10, 101)
Y = X**2

fig = wplt.Figure(figsize=(10, 10))
fig.plot(X, Y)
fig.title("Square funcion")
fig.preview()

.plot(X, Y, scatter=False, label=None, width=1)

Add plot of coordinates from X and Y. A figure can contain multiple plots, and they all pick a different line or point color.

Parameters:

  • X (np.array): Array of x-coordinates.
  • Y (np.array): Array of Y-coordinates.
  • scatter (bool): Choice of scattering points instead of drawing a line through them.
  • label (string): Label to display inside legend.
  • width (int): Width of line or diameter width for points.

Usage:

fig.plot(X, Y, label="Plot 1")

.xrange(x_left, x_right)

Show all x-values from x_left to y_right.

Parameters:

  • x_left (int): Leftmost range of X-axis.
  • x_right (int): Rightmost range of X-axis.

Usage:

fig.crange(-100, 100)  # Show x-values from -100 to 100.

.yrange(y_bottom, y_top)

Show all y-values from y_bottom to y_top.

Parameters:

  • y_bottom (int): Bottom range of Y-axis.
  • y_top (int): Top range of Y-axis.

Usage:

fig.yrange(-100, 100)  # Show y-values from -100 to 100.

.xaxis()

Displays X-axis on your figure.

Usage:

fig.xaxis()

.yaxis()

Displays Y-axis on your figure.

Usage:

fig.yaxis()

.grid(x_steps=1, y_steps=1)

Adds a background grid to your figure. Default is set to strike lines through all integers.

Parameters:

  • x_steps (int): Vertical line seperataion.
  • y_steps (int): Horizontal line seperataion.

Usage:

fig.grid(x_steps=10, y_steps=100)  # Horizontal lines every 100 steps, and vertical lines every 10 steps.

.legend()

Adds a legend to the top left of your figure. This requires you to add labels to one or more of your plots.

Usage:

fig.legend()

.title(title_text)

Adds a title to the top of your figure.

Parameters:

  • title_text (string): Title to display.

Usage:

fig.title("Figure title")

.preview()

Previews a figure with plots added to it. Not available for video (i.e. when using TimeSeries).

Usage:

fig.preview()

.save(path=None)

Saves a figure to file. Either png for static plots, and gif for plots with

Parameters:

  • path (string): Filepath to where to save image. Leave empty for default.

Usage:

fig.save("C:/image.png")

Clone this wiki locally