How do I plot countours with consistent color map?

7 views (last 30 days)
I am trying to generate a set of contour plots. Each plot contains 2 axes showing l/h and r/h data which I want to be able to compare using a single colorbar/colormap. However, I keep getting mismatched colorbars and I m not sure what I am doing wrong. As you can see from the attached plot, my range and ticks match but the colormap is all wonky.
Please advise if you see my error.
Inputs
x = monotonically increasing vector of n x locations
y = monotonically increasing vector of m y locations
p1 = m x n array of l/h pressure values
p2 = m x n array of r/h pressure values
Code
% Find Plot Limits
mx=ceil(max(max[p1,p2])); % find max pressure in l/h and r/h data sets
mn=floor(min(min([p1,p2])); % find min pressure in l/h and r/h data sets
delta=(mx-mn)/40; % delta for contour plot
% Create Figure
figure1=figure('Color', [1 1 1]);
% Axis 1
axes1=axes('Parent', figure 1,'BoxStyle','full','Layer','top','visible','off'); %create l/h axis
hold(axes1,'on')
contour (x,y,p1,[mn:delta:mx],'Fill', 'on');
set (colorbar, 'Limits', [mn,mx])
% Axis 2
axes2=axes('Parent', figure 1,'BoxStyle','full','Layer','top','visible','off'); %create r/h axis
hold(axes2,'on')
contour (x,y,p2,[mn:delta:mx],'Fill', 'on');
set (colorbar, 'Limits', [mn,mx])
  3 Comments
Matt Brown
Matt Brown on 23 Jan 2018
I am not sure if I understand your question. I call it twice because I thought I had to set it for each axis/plot. Is this not the case?
You are correct in assuming this is not the real code. I have boiled it down for simplicity. Removed position vectors, annotations, etc... Things that shouldn't affect the contour plot colormap.
Matt Brown
Matt Brown on 23 Jan 2018
Edited: Matt Brown on 23 Jan 2018
I went in and commented out the set(colorbar) command. I get the same color map now, but the range and ticks are off. I guess that is what is causing the issue, but I am not sure how to get the end result I am after.
I want to have the same max/min in the colorbar and have the same pressure value correlate to the same color between both plots. I thought specifying [mn:delta:mx] in the contour plot level list would have done that.

Sign in to comment.

Accepted Answer

Matt Brown
Matt Brown on 24 Jan 2018
Not sure this is the most elegant way, but rather than plotting things on 2 separate axes I was able to achieve my end goal by putting both contours on one axis and offsetting the y coordinate of the r/h data.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!