Adorning your graph

In the first page of the tutorial, we created a very basic graph:

x = -10:0.1:10;

qplot(x, sin(x));

Compared with vanilla Matlab, the result was very sparse: the data are plotted, but there are no labeled axes or anything. The reason for this is QPlot’s design philosophy: you, the user, know what you want your graph to look like; automatic defaults are almost certain to be wrong.

Fortunately, adding axes is quite easy. Here are a few suggestions for adding x-axes:

qxaxis(-1.1, [-10:5:10]);

qxaxis(-1.4, [-10 10], [], 'Time');

qxaxis(-1.7, [-10 10], [-2*pi 0 2*pi], {'-2π', '0', '2π'}, 'Angle');

As you can tell, you need to specify not just what you want your axis to look like, but also where you would like it to appear: the first argument to qxaxis is the y-position of the axis. Following that, you can specify the range the axis should space ([-10 10]), where to place ticks ([-10:5:10]), what to print by those ticks ({'-2π', '0', '2π'}) and what to name the axis (Time). Any or all of these elements may be specified or omitted as required.

By the way, does your text look cut off? Type qshrink to invoke QPlot’s shrink-to-fit algorithm.

Naturally, there is an equivalent qyaxis command. And the appearance of the axis may be further customized. For instance:

qfont Times b 15

qaxshift 5

qticklen 10

qtextdist 5

qyaxis(-10, [-1:1], 'Height');

(qfont specifies font properties; qaxshift causes the axis to be rendered some number of points to the left of the location specified; qticklen specifies how long the axis ticks are (in points); and qtextdist specifies how far from the ticks the text should be rendered. Note that all of these customizations are specified before the plot command (qyaxis(...)) that they modify, unlike in Matlab where the set command is applied after the graphical element to be modified has been created.)

Having learned how to label our axes, let’s return to plotting of data on the next page.

(C) Daniel Wagenaar, 2014. This web page is licensed under the GNU Free Documentation License.