How do I plot countours with consistent color map?

3 次查看(过去 30 天)
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 个评论
Matt Brown
Matt Brown 2018-1-23
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 2018-1-23
编辑:Matt Brown 2018-1-23
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.

请先登录,再进行评论。

采纳的回答

Matt Brown
Matt Brown 2018-1-24
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by