Bart chart absolute width
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Star Strider
el 10 de Feb. de 2019
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.
0 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!