How to set axis background color of inset image?

15 ビュー (過去 30 日間)
Amy M
Amy M 2023 年 8 月 5 日
コメント済み: Voss 2023 年 8 月 5 日
I want the region of an inset figure that contains the actual axis information to be solid white so that reference lines on the main figure don't get confused.
Currently my code and the output looks like this:
A = [30,480;30,250;40,250;8,60;120,366;32.5,665;12.5,237.5;60,450;110,380;61,305;122,610;37,226;120,492];
B = [80 60; 100 80; 122 110; 83 175; 310 139.5];
AR = A(:,1)./A(:,2);
figure()
scatter(A(:,2),A(:,1),80,'filled','o','MarkerEdgeColor','black','LineWidth',1)
hold on
scatter(B(:,2),B(:,1),85,'filled','^','MarkerFaceColor','#A2142F','MarkerEdgeColor','black','LineWidth',1)
ax = gca;
ax.XAxis.FontSize = 14;
ax.YAxis.FontSize = 14;
xlabel('Width (m)');
ylabel('Height (m)');
legend('Lava Domes','Lava Spines','Location','best','FontSize',14);
pos = get(ax,'Position');
inset = axes('Parent',gcf,'Position',[0.5900 0.25 0.2948 0.4300]);
hold(inset);
Current plot held
histogram(AR,'FaceColor','#0072BD','EdgeColor',[0 0 0],'FaceAlpha',1)
xlabel('Aspect Ratio (H/W)','FontSize',14);
ylabel('Count','FontSize',14);
inset.XAxis.FontSize = 12;
inset.YAxis.FontSize = 12;
As you can see, the number labels of the axes overlap the data, is there a way to make the background of the axes solid white so that it sits on top of the data? I have tried changing the axis colour but that only changes the colour of the text, not the actual background. The only thing I can think of is placing a rectangle and having the histogram on top of that.
Thanks!
  2 件のコメント
Image Analyst
Image Analyst 2023 年 8 月 5 日
Doing that may cover some data points. I think plotting an inset over a graph beneath it is just confusing. Personally, as a consumer of your data, I'd rather see two separate graphs.
Amy M
Amy M 2023 年 8 月 5 日
This isn't the final figure, just some sample data to highlight what I'm actually trying to do and how I've set it up.

サインインしてコメントする。

採用された回答

Voss
Voss 2023 年 8 月 5 日
編集済み: Voss 2023 年 8 月 5 日
You can create a panel, and put the inset axes in it. (Of course, the panel may obscure some data points.)
Something like this:
A = [30,480;30,250;40,250;8,60;120,366;32.5,665;12.5,237.5;60,450;110,380;61,305;122,610;37,226;120,492];
B = [80 60; 100 80; 122 110; 83 175; 310 139.5];
AR = A(:,1)./A(:,2);
figure()
scatter(A(:,2),A(:,1),80,'filled','o','MarkerEdgeColor','black','LineWidth',1)
hold on
scatter(B(:,2),B(:,1),85,'filled','^','MarkerFaceColor','#A2142F','MarkerEdgeColor','black','LineWidth',1)
ax = gca;
ax.XAxis.FontSize = 14;
ax.YAxis.FontSize = 14;
xlabel('Width (m)');
ylabel('Height (m)');
legend('Lava Domes','Lava Spines','Location','best','FontSize',14);
inset_panel = uipanel( ...
'Parent',gcf, ...
'Position',[0.5405 0.15 0.3804 0.5276], ...
'BackgroundColor','w', ...
'BorderType','none');
inset = axes('Parent',inset_panel,'OuterPosition',[0 0 1 1]);
hold(inset);
Current plot held
histogram(AR,'FaceColor','#0072BD','EdgeColor',[0 0 0],'FaceAlpha',1)
xlabel('Aspect Ratio (H/W)','FontSize',14);
ylabel('Count','FontSize',14);
inset.XAxis.FontSize = 12;
inset.YAxis.FontSize = 12;
  2 件のコメント
Amy M
Amy M 2023 年 8 月 5 日
That's perfect, thank you so much!
Voss
Voss 2023 年 8 月 5 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by