Adding XTickLabels to grouped individual bar graphs and plot on hold
9 views (last 30 days)
Show older comments
I have two types of plots.
1) In fist case I need to label individual bar graphs in the grouped bar plot. Here is the example
a=[4.54545454545455,88.6363636363636,27.2727272727273,77.2727272727273,54.5454545454545;31.8181818181818,61.3636363636364,38.6363636363636,68.1818181818182,54.5454545454545;54.5454545454545,61.3636363636364,59.0909090909091,54.5454545454545,50;68.1818181818182,27.2727272727273,56.8181818181818,34.0909090909091,50;90.9090909090909,11.3636363636364,68.1818181818182,15.9090909090909,40.9090909090909];
b=[0.400000000000000,0.550000000000000,0.700000000000000,0.850000000000000,1;1.39000000000000,1.54000000000000,1.69000000000000,1.84000000000000,1.99000000000000;2.34000000000000,2.49000000000000,2.64000000000000,2.79000000000000,2.94000000000000;3.36000000000000,3.51000000000000,3.66000000000000,3.81000000000000,3.96000000000000;4.29000000000000,4.44000000000000,4.59000000000000,4.74000000000000,4.89000000000000];
figure,
hold on
for i=1:5
bar(b(i,:),a(:,i))
end
figure,
hold on
for i=1:3
plot(b(i,:),a(:,i))
end
For the bar plot, I like to lable on the horizontal as shown in figure, the numbers are stored in an other matrix, say b
2) Similarly, I also want to XTickLables using values in b for the line plot.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1066340/image.png)
0 Comments
Answers (1)
RAGHUNATHRAJU DASHARATHA
on 20 Sep 2022
As per my understanding you want to add XTickLabels to grouped individual bar graphs and plot
I would like to demonstrate it using your code with some changes
a=[4.54545454545455,88.6363636363636,27.2727272727273,77.2727272727273,54.5454545454545;31.8181818181818,61.3636363636364,38.6363636363636,68.1818181818182,54.5454545454545;54.5454545454545,61.3636363636364,59.0909090909091,54.5454545454545,50;68.1818181818182,27.2727272727273,56.8181818181818,34.0909090909091,50;90.9090909090909,11.3636363636364,68.1818181818182,15.9090909090909,40.9090909090909];
b=[0.400000000000000,0.550000000000000,0.700000000000000,0.850000000000000,1;1.39000000000000,1.54000000000000,1.69000000000000,1.84000000000000,1.99000000000000;2.34000000000000,2.49000000000000,2.64000000000000,2.79000000000000,2.94000000000000;3.36000000000000,3.51000000000000,3.66000000000000,3.81000000000000,3.96000000000000;4.29000000000000,4.44000000000000,4.59000000000000,4.74000000000000,4.89000000000000];
figure,
hold on
for i=1:5
bar(b(i,:),a(:,i))
end
p=[b(1,:) ,b(2,:), b(3,:) ,b(4,:) ,b(5,:)];
xticks(gca,p)
text(0.5 , -12 ,'Text 1','FontSize',12)
text(1.5 , -12 ,'Text 2','FontSize',12)
text(2.5 , -12 ,'Text 3','FontSize',12)
text(3.5 , -12 ,'Text 4','FontSize',12)
text(4.5 , -12 ,'Text 5','FontSize',12)
figure,
hold on
for i=1:3
plot(b(i,:),a(:,i))
end
p=[b(1,:) ,b(2,:), b(3,:) ];
xticks(gca,p)
text(0.5 , -12 ,'Text 1','FontSize',12)
text(1.5 , -12 ,'Text 2','FontSize',12)
text(2.5 , -12 ,'Text 3','FontSize',12)
text(3.5 , -12 ,'Text 4','FontSize',12)
text(4.5 , -12 ,'Text 5','FontSize',12)
0 Comments
See Also
Categories
Find more on Labels and Annotations 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!