Section 6.7 Plot Formatting and Style
What are the major deficiencies of the plots that I have been showing?
Poor style! No axes labels, title, or other information that tells you what the data are that I am displaying.
The plot command gives you only a bare plot. There are two ways to add information to your plots: interactively and by using built-in commands, the latter being of most use in programming.
Subsection 6.7.1 Interactive Method
After creating your plot, you can interactively add features to it, including axis labels, a title, a legend, a colorbar, text, lines, arrows, and more.
These changes that you make to your plot interactively are not saved.
Subsection 6.7.2 Plot Formatting Commands
Plot formatting commands can be used to add features to your plots without needing to interactively add them each time a plot is created.
Labels:
>> xlabel('text for x-axis label')
>> ylabel('text for y axis label')
>> title('text for a plot title')
>> text(x,y, 'text placed on plot at position (x,y)')
Text in labels can be formatted using LaTeX commands. These are text modifiers that appear in the string, similar to escape sequences. Modifiers affect single characters or groups of characters that are bracketed {}.
Subsection 6.7.3 LaTeX Commands
Here are a few useful LaTeX commands to get you started!
Text Modifiers | |
\bf |
bold face text |
\it |
italic text |
\rm |
normal text |
^ |
superscript |
_ |
subscript (underscore) |
Greek Symbols | |||
\alpha |
\(\alpha\) | \sigma |
\(\sigma\) |
\beta |
\(\beta\) | \Delta |
\(\Delta\) |
\gamma |
\(\gamma\) | \Gamma |
\(\Gamma\) |
\theta |
\(\theta\) | \Lambda |
\(\Lambda\) |
\pi |
\(\pi\) | \Omega |
\(\Omega\) |
For example:
>> xlabel('{\bf Frequency} (s^{-1})') >> ylabel('{\bf Conductivity} (\Omega^{-1} m^{-1})')
Subsection 6.7.4 Legend
With multiple graphs in a single plot it is often necessary to identify each graph in a legend.
>> legend('string1','string2’,...., ‘Location’, Value)
Legend Locations | |
'eastoutside' |
outside right |
'best' |
least interference |
'northeast' |
upper right (default) |
'northwest' |
upper left |
'southwest' |
lower left |
'southeast' |
lower right |
... |
>> legend('cos(x)', 'sin(x)', 'cos(x)*sin(x)', 'location', 'southeast')
Subsection 6.7.5 Additional Text Properties
Several other properties of the text in the text command can be modified using PropertyName and PropertyValues.
>> text(x,y, 'text', 'PropertyName', PropertyValue)
Property Name | Effect |
Rotation |
orientation of text |
Fontsize |
size of font in points (10 default) |
Color |
color of text from table |
Linewidth |
width of line around text (0.5 default) |
EdgeColor |
color of line around text |
and others... |
>> text(1,-.5,'some text here!', 'Rotation',45) >> text(7,-.5,'or here!', 'Rotation',-45, 'Color','r')
Subsection 6.7.6 Axes and Grid
When a plot is created the axes are scaled according to the minimum and maximum values over which the abscissa and ordinate ranges.
It is possible to change the range of values over which the data is plotted using the
axis()
command.Function | Effect |
axis() |
specify the ranges explicitly |
axis equal |
use the same scale for both x and y |
axis square |
make the plot square |
axis tight |
make limits exactly range of data |
v = axis |
gives you limits so that you can use them |
grid on |
turn on a grid |
grid off |
turn off the grid (default) |
>> axis([-pi/2,7*pi/2, -1.5,1.5]) >> axis square >> grid on