Jame
Jame

Reputation: 3854

Missing vertical tick when using boxplot in matlab 2014a

I am using boxplot to draw my data using matlab 2014a. I used below code to plot my data and rotate my xlabel. However, it lost the vertical tick in figure. Could you see my expected figure (right side) and help me to add that tick in below code. Thanks

figure(1);
set(gcf,'color','w');
hold on;
rotation = 25;
fontSize = 12;
str={'Test 1','Test 2'};
x1 = normrnd(5,1,100,1);
x2 = normrnd(6,1,100,1);    
ax1=subplot(1,2,1);  boxplot([x1, x2]); title('This is result for above code','FontSize',  fontSize); 
% ylim([0 1]);

text_h = findobj(gca, 'Type', 'text');

for cnt = 1:length(text_h)
     set(text_h(cnt),   'FontSize', fontSize,...
                        'Rotation', rotation, ...
                        'String', str{length(str)-cnt+1}, ...
                        'HorizontalAlignment', 'right')
end  
set(ax1, 'fontsize', fontSize);
set(findobj(ax1,'Type','text'),'FontSize',  fontSize);
ylabel('Temp')

enter image description here

Upvotes: 1

Views: 147

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112659

boxplot doesn't automatically create xticks in Matlab R2014a and older versions (it does in R2015a, and probably in R2014b too).

You can add the xticks manually as follows:

set(ax1, 'xtick', [1 2])

Upvotes: 1

Related Questions