Axes and Figure Formatting
Thus far we have focused on controlling the appearance of lines on a Matlab axes. Let’s take it one step further and work on the appearance of the figure and axes. This will expand control beyond simply lines and allow one to achieve an overall presentation that is desired. First lets add a property that will determine if parent formatting is to be performed. Here the axes and figure are considered the parents.
Notice that we’ve set the isFormattingParents property to 1 inside of the constructor. This means that by default parent formatting will be enabled.
Adding the Formatting Code
First create a function named formatParents. The job of this method is to house the code that performs the axes and figure formatting. Next we need to call this method within the plot method if parent formatting is enabled. The code to perform these actions is shown below.
-Side Note –
One handy feature of Matlab classes is the ability to view the available properties and methods at the command line. This can be done by first creating an instance of a class. After typing the object name followed by a period and then the tab key, Matlab will bring up a list of the properties and methods associated with the object. This is shown below.
Having such a feature available means that less typing is required to get a method name or property name on the screen. In turn, this makes more descriptive property and method names attractive (you may have noticed my wordy variable names). For the Visual Studio user’s out there, I know you are all scoffing at this weak version of intellisense; and I’m right there with you! I hope to see a more intellisense-like display of object information in future releases of Matlab….but this is a step in the correct direction.
Test Out New Formatting
Back to parent formatting….As we have done in the past plotting series, a simple loop around a plot call is used to produce the plot shown below. Notice that the background color is now gray and gridlines are drawn on the axes background. The text on the axes has also been enlarged.
These are merely settings that I prefer. Any desired parent formatting could be performed.
Wrap Up and Next Time
Up to this point we’ve created a functional plotting engine that controls many aspects of visualizing data. In this example, we added figure and axes formatting. This type of formatting could be greatly extended to include other objects outside of merely figures and axes. Other candidate objects that one could format would include axes labels, figure titles and legends to name a few. More to come next time!