19.8: Labeling Axes

Matlab and Octave Programming for STEM Applications · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    19.8: Labeling Axes

    The plots in this chapter have labels on the axes, and one of them has a legend, but I didn’t show you how to do that. Let’s do it now.

    The functions to label the axes are xlabel and ylabel:

    xlabel('Time (hours)')
    ylabel('Population (billions of cells)')

    The function to generate a legend is legend:

    legend('euler', 'ode45')

    The arguments are the labels for the lines, in the order they were drawn. Usually the legend is in the upper-right corner, but you can move it by providing an optional argument called Location:

    legend('euler', 'ode45', 'Location', 'northwest')

    Finally, save the figures using saveas:

    saveas(gcf, 'runge.eps', 'epsc')

    The first argument is the figure we want to save; gcf is a MATLAB command that stands for “get current figure,” which is the figure we just drew. The second argument is the filename. The extension specifies the format we want, which is Encapsulated PostScript (.eps). The third argument tells MATLAB what driver to use. The details aren’t important, but epsc generates figures in color.


    This page titled 19.8: Labeling Axes was last modified on Wed, 13 Jul 2022 23:59:17 GMT and is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Allen B. Downey (Green Tea Press) via source content that was edited to the style and standards of the LibreTexts platform.