How do I plot countours with consistent color map?

조회 수: 9 (최근 30일)
Matt Brown
Matt Brown 2018년 1월 23일
답변: Matt Brown 2018년 1월 24일
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