Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overlay a pcolor plot with a contour plot that uses a different colormap?

Minimum example that does not achieve it:

[X,Y,Z] = peaks;
figure;
pcolor(X,Y,Z);
shading flat;
hold all;
axes;
contour(X,Y,Z);
colormap gray;  % this should only apply to the contour plot axes...
axis off;       % ... but it doesn't

This shows both the contour plot and the pseudo colour plot in the grayscale colourmap. However, what I want to achieve is only turning the contours gray.

This is just a minimalistic example, in reality the contour plot is of different data that has a different range, so two independent caxis settings are required as well.

like image 296
Tobias Kienzler Avatar asked Mar 28 '11 10:03

Tobias Kienzler


People also ask

What is a filled contour plot?

Rather than having discrete contour lines, “filled” contour plots shade the regions between contours according to a colormap. Contour lines themselves are not plotted. Use Contour Plot in combination with this VI to display lines.

How do you contour a plot?

A contour plot is a graphical technique for representing a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format. That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs.

How do you plot in 3D contour?

To plot 3D contour we will use countour3() to plot different types of 3D modules. Syntax: contour3(X,Y,Z): Specifies the x and y coordinates for the values in Z. contour3(Z): Creates a 3-D contour plot containing the isolines of matrix Z, where Z contains height values on the x-y plane.


1 Answers

You can fix the problem by catenating two colormaps, and making sure that the values of the functions are such that they access the right part of the colormap:

cm = [jet(64);gray(64)];
figure,
pcolor(X,Y,Z)
shading flat
hold on
%# Z in the contour starts after the maximum
%# of Z in pcolor
contour(X,Y,Z-min(Z(:))+max(Z(:))+2,'LineWidth',2)
%# apply the colormap
colormap(cm)

enter image description here

For a more convenient solution, you may also want to have a look at this file exchange pick of the week

like image 137
Jonas Avatar answered Nov 11 '22 20:11

Jonas