Last post we defined the mPlot class and added properties to define the visual appearance of line objects. A method to draw data on the current axes object was also added. This time we are going to add some handy functions to make interaction with the mPlot object easier.
Interacting With plotCounter
As we saw last time, plotCounter is used to determine which visual styles to apply to the current line. Recall from last time that we had to increment the plotCounter property external to the class….as shown below.
While we’re on this topic, add one property named isAutoIncrementing. This will be a boolean value, either 1 or 0. If the value of isAutoIncrementing equals 1, a method will automatically increment plotCounter each time a line is drawn to an axes. Notice below that we had to add an if-then statement within the plot function to increment plotCounter if auto-incrementing is enabled.
This property will also need to be initialized within the constructor of mPlot. This will eliminate the need to call an increment method every time we plot the next line. Of course, there may be some cases where you don’t want this type of functionality. In that case simply set isAutoIncrementing to zero and you’re back in full control.
plotCounter Methods in Action
The short lines of code below will be used to test out the new methods within mPlot. Check out the comments for more information….but all we have done here is 1) plot on an axes while manually incrementing, 2) reset the plotCounter to zero, 3) enable auto-incrementing and 4) plot on a different axes.
After executing the code the plots below are produced.
So regardless of technique, both produce the same result. But when plotting multiple lines on a single axes, auto-incrementing can be advantageous. One may even choose for this to be the default. In this case, simply set isAutoIncrementing to 1 inside of the mPlot constructor. Then each time you instantiate mPlot auto-incrementing will be enabled.
In the next part of this series we will extend formatting beyond lines; we will dive into altering the appearance of the axes and figure.