insert one of bar graph "inside" the other
2 views (last 30 days)
Show older comments
Hello! I have two bar graphs. I would like to insert one of these graphs "inside" the other. Is it possible to do this?
For example like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1448442/image.png)
0 Comments
Accepted Answer
Star Strider
on 2 Aug 2023
Edited: Star Strider
on 2 Aug 2023
EDIT — (2 Aug 2023 at 17:29)
Added ‘Example’.
Example (using ‘CountArray_S’) —
LD1 = load(websave('CountArray_S','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1448127/CountArray_S.mat'));
CountArray_S = LD1.CountArray_S;
Lv1 = ismember(CountArray_S(:,1), 65:74); % Select 'x'-Values For Second 'ases'
figure
ax1 = axes('Position',[0.1 0.1 0.7 0.7]);
ax2 = axes('Position',[0.30 0.35 0.48 0.40]);
hbh(1) = barh(ax1,CountArray_S(:,1), CountArray_S(:,2), 'FaceColor','r', 'EdgeColor','none');
hbh(2) = barh(ax2,CountArray_S(Lv1,1), CountArray_S(Lv1,2), 'FaceColor','r', 'EdgeColor','none');
Make appropriate changes to get the desired result.
.
4 Comments
Star Strider
on 3 Aug 2023
In this instance, the axes that the labels apply to must be explicitly stated.
I created axis labels for both axes here in the event that you may also want them for the zoomed axes —
load CountArray_A.mat
load CountArray_A_zoom.mat
x_A = CountArray_A(:,1).';
y_A = CountArray_A(:,2);
figure();
ax1 = axes('Position',[0.1 0.1 0.7 0.7]);
ax2 = axes('Position',[0.3 0.5 0.5 0.3]);
graph_A = barh(ax1,x_A,y_A,'FaceColor',[1 0 0],'EdgeColor','none');
name_A = "analysis A";
% legend({name_A},'Location','southeast','Orientation','horizontal')
x_A_zoom = CountArray_A_zoom(:,1).';
y_A_zoom = CountArray_A_zoom(:,2);
% figure();
graph_A_zoom = barh(ax2,x_A_zoom,y_A_zoom,'FaceColor',[1 0 0],'EdgeColor','none');
xlabel(ax1,'Repetition', 'FontSize', 13)
ylabel(ax1,'Numbers', 'FontSize', 13)
xlabel(ax2,'Repetition Zoomed', 'FontSize', 8)
ylabel(ax2,'Numbers Zoomed', 'FontSize', 8)
.
More Answers (0)
See Also
Categories
Find more on 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!