In this tutorial I will show how to make six different 3D surface and contour plots in Matlab, as well as how to change common settings. For this tutorial, I will be generating my data from my mathematical model of firefly luciferase reaction with its intermediate, luciferyl-AMP.
If you have a two dimensional matrix you can make a 3D plot. One dimension is the values corresponding to the matrix rows, one dimension is the values corresponding to the matrix columns, and the 3rd dimension corresponds to the actual elements of the matrix. In Matlab, the values of the rows and columns can be simply defined using the “meshgrid” function. This is illustrated in the 4th example below.
- In the first example, I show a surface plot with a contour map underneath. Matlab has a variety of colormaps available (see the list here). Various features can be altered both by commands and by using the plot property editor.
- Next, the same data is illustrated using a contour map only.
- Contours and surfaces can be layered in Matlab by using “hold on” command. The range and scale of the colormap might need to be altered to cover the full range of both data sets. This is covered in example 5.
- Here interpolation is illustrated by creating a meshgrid. This allows me to create a smoother surface by interpolating additional points between the matrix elements.
- A heatmap is another type of 3D plot, where the view is constricted to be the XY plane.
- Here, the same heatmap is plotted, but the range of the colormap is altered so that it colors a smaller range of values. This simulated data covers a huge range, from zero to 8 orders of magnitude. By ignoring values below 2 orders of magnitude, it highlights the sharp increase in value as you increase kon for early time points.
Example code is visible in the following PDF, and also downloadable here.