19.8: Labeling Axes
- Page ID
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('Time (hours)') ylabel('Population (billions of cells)')
The function to generate a legend is
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
legend('euler', 'ode45', 'Location', 'northwest')
Finally, save the figures using
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.