

We can also customize the fonts, lines and other properties for individual dimensions. For example, we can set the exponent to a negative value like -6. We can set the Exponent to other values to specify a particular power of 10. The previous section set the y-axis Exponent to 0 to suppress the usual graphics behavior of factoring out large powers of 10. A common mistake is to use %d for doubles. The comma flag can be used with any of the format types. The comma flag "," is an extension which is only supported in graphics and is not available generally in MATLAB. We can use the format %,d to get integers with commas inserted every three digits. Suppose now our income ranges from 0 to 30 million instead of just 0 to 30. ax.YAxis.TickLabelFormat = '\x20AC %.2f' Prepend the euro (and a single space) to our existing format. The printf format \xNNNN produces a single character with unicode hexidecimal value NNNN. The unicode codepoint for the euro, for example, is 02AC in hexidecimal. We can do even better by prepending a currency symbol. ax.YAxis.TickLabelFormat = '%.2f' īy the way, does anyone know the true history behind the abbreviations in printf formats? The format g presumably stands for "general" but I've never found real proof. The format %.2f specifies exactly 2 digits of precision after the decimal point. We can show the tick labels with exactly two decimal places by customizing the tick label format. First, let's make the plot without any y-axis customization.


The next several sections will step through the process slowly. Here is the same dataset as before except this time we'll customize the y-axis for currency values. Suppose we plot currency data instead of temperature data. step = 1 Īx.YAxis.MinorTickValues = setdiff(0:step:30,ax.YTick) For example, let's set the minor step to be one degree. We can control the spacing of the minor tick using the new MinorTickValues property. Let's turn on the grids to make it easier to read off values from the chart. So we have "escape the escape" by writing \\. Why \\circ and not just \circ? The reason is that \ is the escape character for both TeX and printf formats.

These formats use %g to stand for the default numeric formatting and \\circ to get the TeX command for a degree symbol. The syntax for the TickLabelFormat property is a printf format. Let's customize the y-axis tick labels to contain a degree symbol. Then you use the XAxis, YAxis or ZAxis properties to customize a particular axis. To access the new features, you get the current axes object by storing the result of gca in a variable. To begin, let's plot some sample temperature data across a full year.
