Plotting line plots and histogram in a single figure
4 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!