How to set axis background color of inset image?

14 vues (au cours des 30 derniers jours)
Amy M
Amy M le 5 Août 2023
Commenté : Voss le 5 Août 2023
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 commentaires
Image Analyst
Image Analyst le 5 Août 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 le 5 Août 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.

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 5 Août 2023
Modifié(e) : Voss le 5 Août 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;
  2 commentaires
Amy M
Amy M le 5 Août 2023
That's perfect, thank you so much!
Voss
Voss le 5 Août 2023
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by