Overlay contour and line plot

Hi Folks, I've got a 2D contour plot (x,y,z) and I want to overlay a line plot (x,y). The two graphs share the same x values. The hold on functions don't seem to help much. Any pointers?
fig1 = figure(1);
hFig = contour(gEmiFreq,gAbsFreq,MAmpl,c0.*SFac,...
'LineStyle','-','LineWidth',CntlineW);
line(DiagnlLine(1,:), DiagnlLine(2,:), 'LineStyle', '-', 'Color', [0 0 0],'LineWidth',LineW+.5);
axis(AxisDim);
caxis([0 1]);
set(gca,'xtickMode', 'manual', 'ytickMode', 'manual','LineWidth',2);
axis square; colormap jet;% colorbar;
hold on
plot(gEmiFreq(1,:),NormRef);
Normref is a 1x1024 laser spectrum and MAmpl,gEmiFreq, and gAbsFreq are 76x1024 arrays

답변 (1개)

Star Strider
Star Strider 2015년 1월 19일

0 개 추천

I don’t know what the problem is, since what you describe should work. You didn’t post your code, so I can’t respond with a specific solution.
See 2D Filled Colour Plot for my previous (Accepted!) solution to a similar problem.

댓글 수: 9

I don’t have your data, so I can’t run your code.
See if rearranging your code to put the hold calls in a different order solves your problem:
fig1 = figure(1);
hFig = contour(gEmiFreq,gAbsFreq,MAmpl,c0.*SFac,...
'LineStyle','-','LineWidth',CntlineW);
hold on
line(DiagnlLine(1,:), DiagnlLine(2,:), 'LineStyle', '-', 'Color', [0 0 0],'LineWidth',LineW+.5);
plot(gEmiFreq,NormRef);
hold off
axis(AxisDim);
caxis([0 1]);
set(gca,'xtickMode', 'manual', 'ytickMode', 'manual','LineWidth',2);
axis square; colormap jet;% colorbar;
Image Analyst
Image Analyst 2015년 1월 19일
Can you demo with something standard, like the peaks() image?
Brian
Brian 2015년 1월 19일
편집: Brian 2015년 1월 20일
Yes, I hope this is more understandable! I tried moving the hold calls around, and it would do things switch which plot I saw but not overlay
clear all
NRow = 5; NCol = 5;
c0 = (0:.02:1);
MDim(1:4) = [[1475.40680000000,1511.70650000000,-1510.92820000000,-1475.06230000000;]];
[gEmiFreq, gAbsFreq] = meshgrid( linspace( MDim(1), MDim(2), NCol),... linspace( MDim(3), MDim(4), NRow) ); MAmpl0 = abs(peaks(5)); MAmpl = MAmpl0/max(max(MAmpl0)) laser = [0 .5 1 .5 0]; fig1 = figure(1); hold on hFig = contour(gEmiFreq,gAbsFreq,MAmpl,c0);
caxis([0 1]); set(gca,'xtickMode', 'manual', 'ytickMode', 'manual','LineWidth',2); axis square; colormap jet;% colorbar; plot(gEmiFreq(1,:),laser);
Star Strider
Star Strider 2015년 1월 19일
I have no idea. I cannot run your code, so I can only wish you luck.
Brian
Brian 2015년 1월 20일
Thanks Star Strider, this is my first time using a forum and I forgot to clear the memory when I was making the dummy code. Anyway, this guy should execute. Thank you for sticking around!
Star Strider
Star Strider 2015년 1월 20일
My pleasure!
Is your problem solved?
Brian
Brian 2015년 1월 20일
Unfortunately no, the issue is that I don't see the second plot overlayed on the contour plot.
working test code:
clear all
NRow = 5; NCol = 5;
c0 = (0:.02:1);
MDim(1:4) = [[1475.40680000000,1511.70650000000,-1510.92820000000,-1475.06230000000;]];
[gEmiFreq, gAbsFreq] = meshgrid( linspace( MDim(1), MDim(2), NCol),...
linspace( MDim(3), MDim(4), NRow) );
MAmpl0 = abs(peaks(5));
MAmpl = MAmpl0/max(max(MAmpl0))
laser = [0 .5 1 .5 0];
fig1 = figure(1);
hold on
hFig = contour(gEmiFreq,gAbsFreq,MAmpl,c0);
caxis([0 1]);
set(gca,'xtickMode', 'manual', 'ytickMode', 'manual','LineWidth',2);
axis square; colormap jet;% colorbar;
plot(gEmiFreq(1,:),laser);
Star Strider
Star Strider 2015년 1월 20일
You probably won’t be able to overlay it on the contour plot, unless you use something like plotyy. The reason is that the y values are so different. Experiment with that to see if it solves your problem.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

질문:

2015년 1월 19일

댓글:

2015년 1월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by