Data analysis, Math Modeling, Visualization

Tutorial: Six 3D Surface and Contour Plots in Matlab

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.

  1. 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.
  2. Next, the same data is illustrated using a contour map only.
  3. 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.
  4. Here interpolation is illustrated by creating a meshgrid. This allows me to create a smoother surface by interpolating additional points between the matrix elements.
  5. A heatmap is another type of 3D plot, where the view is constricted to be the XY plane.
  6. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s