plotAddShape

Purpose

Adds an arrow, line, ellipse or rectangle to an existing graph.

Format

plotAddShape([myAnnotation, ]which_shape, x_start, y_start, x_end, y_end)
Parameters:
  • myAnnotation (struct) – Optional argument, an instance of a plotAnnotation structure.

  • which_shape (string) –

    indicating which shape to create, options include:

    • ”ellipse”

    • ”line” (to which you may add an arrow head)

    • ”rectangle”

  • x_start (scalar or Nx1 vector) – the X coordinate for the start of the bounding box for each respective shape.

  • y_start (scalar or Nx1 vector) – the Y coordinate for the start of the bounding box for each respective shape.

  • x_end (scalar or Nx1 vector) – the X coordinate for the end of the bounding box for each respective shape.

  • y_end (scalar or Nx1 vector) – the Y coordinate for the end of the bounding box for each respective shape.

Examples

Add a rectangle

// Draw simple graph
x = rndu(10, 1);
y = rndu(10, 1);
plotScatter(x, y);

// The rectangle will be drawn between
// third and sixth points on the plot
x_start = x[3];
y_start = y[3];
x_end = x[6];
y_end = y[6];

// Shape type will be rectangle
annotation_type = "rectangle";

// Add rectangle to graph
plotAddShape(annotation_type, x_start, y_start, x_end, y_end);

Remarks

plotAddShape() will add shapes to existing graphs. It will not create a new graph, however, if one does not already exist.

Note

The top left corner of the bounding box for the shape will be placed at the coordinates that you specify. The bounding box is rectangular and will, therefore, not touch the edge of an ellipse at that point.

plotAddShape() is not yet supported for surface plots.