Cycling colours effortlessly in multi-line MATLAB plots
Often, one needs to plot many lines in one figure, with each line being a different colour. While this can be done by selecting each line manually and changing its colour using the GUI, it is much faster doing this using DefaultAxesColorOrder. And easy too!
DefaultAxesColorOrder defines the order of colours used when plot is called. For example, if you want to switch from red to blue to green each time you use plot, you need to issue the command
But what do you do when you have more than just three or four colours? I prefer to use rand. Here's how. Let's assume you have twenty lines to draw in the same plot, each with a different colour. First we issue the order of colours to use:
So we have replaced our colour matrix by a matrix of size 20x3 with each row representing a colour. rand will always produce a uniformly distributed random number between 0 and 1. Now that we have defined our colour order, we just have to issue the plot command.
For demonstration purposes, I've just drawn 20 lines with random starting and ending coordinates. See the result below:
I am currently working as a Wireless Technologies Researcher at DOCOMO Euro-Labs. My research is focused on interference and energy-efficiency analysis of next generation heterogeneous cellular networks.