set_plot Documentation

The purpose of set_plot is to make the creation of high-quality graphics in MATLAB easier. This documentation provides many examples for creating a variety of functions in addition to a discussion of the options for the functions.

The main function, set_plot(), uses a system of cascading style options, similar to CSS. This prevents the need to change many options individually for customized graphics styles, but can be somewhat confusing. Thus this documentation also includes a guide to what format options are children of other options, and what happens when apparently conflicting options are given to set_plot().

Installation

To install the set_plot package, simply unzip the file to a good folder (within the 'Documents/MATLAB' folder is a pretty good suggestion) and run the sp_Install() function.

>> ierr = sp_Install
ans =
     0

If the output of this command is zero, the installation was successful. Afterwards, you may delete the .zip file, but do not delete the unzipped folder. To uninstall from MATLAB’s memory, run the following command.

>> sp_Uninstall

This does not delete the set_plot source from your computer, so you will have to do that manually if desired.

Basic Examples

Usage and Basic Plots

This example illustrates the basic usage of set_plot.

>> x = linspace(0, 6, 121);
>> plot(x, sin(x), x, cos(x+sin(4*x))/2)
>> xlabel('Time [s]')
>> ylabel('Amplitude')

And, voilà, you get the following graphic.

_images/sine-plain.png

Now, in a single command, set_plot() can change the fonts, point the axes ticks outward instead of inward, and make several other changes.

>> set_plot('FigureStyle', 'fancy')

The resulting figure, shown below, has many more bells and whistles.

_images/sine-fancy.png

The idea is that running set_plot('FigureStyle', 'journal') will result in a figure that is close to being presentable for publication. Perhaps the most useful aspect of this is creating a figure that is appropriately sized for printing, which is discussed more in the following example.

Figure Sizing and Saving to PDF

Consider the following MATLAB commands to create a simple contour plot.

>> contour(peaks(50))

The resulting graphic, saved as a PNG, is below.

_images/peaks-plain.png

Displayed as such a small graphic, the graphic is almost unreadable. Furthermore, saving to PDF produces the following (including whitespace), which is not at all the expected result.

_images/peaks-page.png

Running set_plot on this figure with no options produces no visible changes to the MATLAB figure window, but results in properly saved PDF files.

>> set_plot(gcf)

The following is the resulting image if saved as a PDF.

_images/peaks-simple.png

If we specify some non-default options to set_plot, there is lots of automatic formatting that is done.

>> set_plot(gcf, 'FigureStyle', 'journal')
_images/peaks-journal.png

Note

As of version 0.9.0, resizing the MATLAB figure window does cause the figure to be resized, whereas in previous versions it would remain the same size, often occupying just the lower left-hand corner of the window. However, this automatic resizing does not transfer to the 'PaperSize' property, meaning that saving to a PDF will not work as expected if you have resized a window.

Indices and tables

Table Of Contents

Next topic

1. Functions

This Page