How to set axis background color of inset image?

8 views (last 30 days)
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 Comments
Image Analyst
Image Analyst on 5 Aug 2023
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 on 5 Aug 2023
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.

Sign in to comment.

Accepted Answer

Voss
Voss on 5 Aug 2023
Edited: Voss on 5 Aug 2023
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;

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!