Plotting line plots and histogram in a single figure

조회 수: 4 (최근 30일)
Hari krishnan
Hari krishnan 2019년 5월 26일
댓글: Hari krishnan 2019년 5월 26일
Hi, I am trying to draw a 'bar' graph in a single figure together with a line plot. I am using an image called 'arena_image' and then line plots are made on on top of this image. What i want to do is to make a bar of vector 'sg' alongside the line plot in the same figure. Any help to solve this will be appreciated. The entire code used in the plotting section is shown below.
arena_image = imread('good_nest_top_for_conflict_edit.png');
h1 = axes ;
cc = hsv(np);
image('XData',[0 6700],'YData',[0 5000],'CData',arena_image) ; % set your limits
set(h1,'YDir','normal');
ax = gca;
ax.YDir = 'reverse';
axis([0 6700 0 5000])
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
h = zeros(1,np);
for ii = 2:25:size(a,1)
ax.Position(3) = 0.65;
k = 0;
t = a(ii,1);
count_gn = rowsum_for_ants_in_gdnest_matrix(ii);
count_bn = rowsum_for_ants_in_bdnest_matrix(ii);
count_hn = rowsum_for_ants_in_arena_except_homenest(ii);
count_ar = rowsum_for_ants_in_field(ii);
sg = [count_gn count_bn count_hn count_ar]; % the value in the vector have to be used for the bar plot
hold on
for jj = 2:2:np*2 % ant handles
x = a(ii,jj);
y = a(ii,jj+1);
k = k + 1;
h(k) = plot(x,y,'--or','MarkerSize',13,'MarkerEdgeColor','b','MarkerFaceColor',[0.5,0.5,0.5]);
hi(k) = text(x, y, label(k), 'VerticalAlignment','bottom', 'HorizontalAlignment','right'); %#ok<SAGROW>
h2(k) = plot(a(max(1,ii-150):ii,jj), a(max(1,ii-150):ii,jj+1),'k','LineWidth',2); %#ok<SAGROW>
set(h2(k),'color',cc(k,:));
end
drawnow
pause(0.01)
delete(h)
delete(hi)
delete(h2)
disp(k)
end
toc
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 5월 26일
use hold one after plot command statement, is there any issue?
Hari krishnan
Hari krishnan 2019년 5월 26일
I want to make the plot on the already loaded image, so i use 'hold on' before the plot function.

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

답변 (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