필터 지우기
필터 지우기

Bart chart absolute width

조회 수: 3 (최근 30일)
Martijn Geelen
Martijn Geelen 2019년 2월 10일
답변: Star Strider 2019년 2월 10일
I create several bar charts during an optimization run in which i do not know the number of bars beforehand. I want all figures to be of the same size. The plots look quite nice, however, if there is only one bar in the figure, it creates a ugly bar chart. I would like to narrow the bar size in case there is one bar with probability 1 (happens quite often). In the attachment it is clearly visible what i mean.
Plot are created with the following code:
for i = 1:N_Locations
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
figure(4+ceil(i/9))
subplot(3,3,i-9*floor(i/9.01))
Rows = find(OrderSize_Empirical(:,1)==Locali(i));
bar(OrderSize_Empirical(Rows(1):Rows(end),3),'FaceColor', [45/255 0 84/255])
Ordersizes = num2cell(OrderSize_Empirical(Rows(1):Rows(end),2));
set(gca,'xticklabel',Ordersizes);
set(gca,'xtick',1:size(OrderSize_Empirical(Rows(1):Rows(end),2)));
str = strcat('Empirical order sizes at location: ',num2str(Locali(i)));
title(str);
xlabel('Order size')
ylabel('Probability')
end

답변 (1개)

Star Strider
Star Strider 2019년 2월 10일
The bar plot widths appear to scale according to the number of bars plotted.
The easiest way might simply be to cheat:
if numel(OrderSize_Empirical(Rows(1):Rows(end),3)) <= 1
patch([-1 1 1 -1]*0.2, [0 0 1 1], [45/255 0 84/255])
xlim([-1 1])
set(gca, 'XTick',0, 'XTickLabel',1)
title(str);
xlabel('Order size')
ylabel('Probability')
end
Experiment to get the result you want.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by