Custom Colormaps in Matlab

Matlab colormaps are usefull to display continuous spatial information. More about colormap usage and options can be found under Matlab help file

However there are cases where the default colormaps are not sufficient. For example the figure below shows the hydraulic head trend over an 80-year simulation. For the areas with positive values the groundwater table is rising while in the areas with negative values the water table drops. However using the default colormap is not easy to distinguish these areas.



To improve the figure we are going to modify the colormap so that the color at value 0 is white, while the positive values will have a blue gradient from deep blue to white, and the negative values a gradient from white to deep red.

After we have plotted the figure we can obtain information about the color axis as follows

In my example cmax = 7.2 and cmin = -5.4.  We can also set our own custom limits for the colors by setting  ax.CLim = [-5 8]; . This will make the cmin = -5 and cmax = 8. This is very useful if one wants consistent colormaps between different figures with different range values.

Next we’ll create a variable that has values that range between cmin and cmax and identify the last row that is negative. In my case that was the 28th row (id = 28).

Next, for each row of the variable lcol we have to assign a color. The lcol(1) corresponds to cmin therefore we want to assign deep red (130,0,0) while the row id corresponds to 0 values which should have white color (255, 255, 255). The last row corresponds to cmax and we will assign deep blue (0, 0, 130). For the remaining row we will interpolate their values as follows:

custom_map is a 64×3 matrix. The columns correspond to the R, G and B normalized color values.

Next we set our custom map to be our colormap

Finally we display it and assign an explanatory text


In the above map we can easily distinguish between the areas where the water table rises or drops.

The full code for the above figure is given below with a minor change that controls the color resolution:




How to make a nice spaghetti in Paraview

In groundwater hydrology streamlines is a very common and effective way to illustrate the groundwater flow field.

Unfortunately because the x-y extend of the groundwater domains is very large, by many orders of magnitude, compared to the z extend this makes the visualization a bit tricky.

The following figure shows the streamlines colored by the velocity along the streamline. The first figure shows the actual size and the next shows the streamlines scaled by a factor of 10.




Those streamlines are thin polylines. To give them volume we can apply the tube filter.

The tube filter however is disabled for lines. We have to convert them first into surfaces.

However before that we will apply  a transformation filter by setting the z scale the desired value.

Next we will apply the Extract surface filter to the transformed streamlines.

And finally the Tube filter with the appropriate radius. Usually the default is too large.

The following figure shows the same streamlines as tubes. In this figure the view angle makes the rendering quite poor but if you zoom in they look nice tubes



To summarize, the sequence of filters over a set of lines to convert them into tubes is the following:

  1. Transform filter by the desired scale factor
  2. Extract surface filter
  3. Tube filter