Add Text to Graph Interactively

This example shows how to interactively add a title, legend, axis labels, and other text to a graph using the figure menus and plot tools.

Add Title and Axis Labels

Create a simple line plot.

x = linspace(1,10);
plot(x,sin(x))

Use the figure Insert menu to add a title and axis labels to the graph. After typing the text, click anywhere outside the text entry box to apply the text.

To modify the title and axis labels, first enable plot edit mode by clicking the Edit Plot button on the figure toolbar.

  • To change the text, double-click it and type new text.

  • To move the text, drag it to a new position.

  • To set text properties, such as the color and font style, right-click the text and use the context menu.

  • To set additional properties, use the Property Editor. Select Show Property Editor from the context menu.

Add Legend

Add a legend to the graph. In the figure, select Insert > Legend.

By default, the legend labels each plotted object with the strings data1, data2, and so on. Change the legend text by double-clicking the text and retyping new text. Display special characters and symbols using TeX markup. For example, use the _ character to display a subscript. For a list of supported TeX markup, see the text Interpreter property.

    Note:   To display a legend with more than 50 entries, you must use the legend function.

To change the legend location, right-click the legend and set the Location option from the context menu. For additional location options, or to modify other legend properties, use the Property Editor. Select View > Property Editor to open the Property Editor. Then, click the legend to access its properties.

Add Annotations to Graph

Add a text box and a text arrow to the graph using the TextBox and Textarrow options from the Insert menu. To add a text box, draw a rectangle and then type the text at the text cursor. To add a text arrow, draw an arrow from tail to head and type the text at the text cursor next to the tail.

See Also

| | | |

Related Examples

Was this topic helpful?