필터 지우기
필터 지우기

Only last plot visible in for loop, different colors between bar and line plot

조회 수: 3 (최근 30일)
Ryan
Ryan 2014년 2월 21일
편집: dpb 2014년 2월 21일
Hi,
I'm having two issues. I have an image that is a bar graph and I'm trying to overlay line plots over it in a for loop. I have two issues. 1) I have three bars (variables) for each day (time on x-axis) and i have three time series lines that I'm trying to make the same color. Each variable (line and bar) being the same color. Any ideas?
2) In an attempt to do this, I created a for loop hoping that I could make each line plot match the color of its respective bar color. However when I do this, only the last line plot shows up.
If I can resolve #1 without a for loop then I don't need #2. Thanks guys!
bar(argentina(:,1:10,4).'); %,colorr(j));
set(gca,'XTick',1:10,'XTickLabel',datstmp(1:10),'YTick',0:5:pcpY);
title('Argentina Regional Mean Daily Precip','FontSize',16,'FontWeight','bold')
ylim([0 pcpY])
ylabel('Daily Totals (mm)')
legend(ARGregions, 'Location','Northwest')
xlim([0 11])
hAxes = gca;
hAxes_pos = get(gca,'Position');
hAxes2 = axes('Position',hAxes_pos);
plot(ApcpCum(j,1:10).','Marker','*','LineWidth',2,'color',color(j,:))
hold on
set(hAxes2,'YAxisLocation','right','Color','none','XTickLabel',[])
ylim([0 150]);
h1_xlim = get(hAxes,'XLim'); % store x-axis limits of first axes
set(hAxes2,'XLim',h1_xlim) % specify x-axis limits of second axes
% code
  댓글 수: 1
dpb
dpb 2014년 2월 21일
편집: dpb 2014년 2월 21일
Why can't you simply set the line() color on the plot to match that of the respective bar desired in 1)?
ADDENDUM: As a general principle it would be much simpler to debug an issue if you could make a trivial demo (using random data is good for this purpose) that demonstrates the problem specifically instead of folks either having to build a demo from scratch or try to make yours work w/o any data.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by