Effacer les filtres
Effacer les filtres

adding two colorbars in the uiaxes of app designer matlab

8 vues (au cours des 30 derniers jours)
Moslem Uddin
Moslem Uddin le 21 Juil 2023
Modifié(e) : Moslem Uddin le 21 Juil 2023
I would like to achieve this in app designer (withing UIAxes). The following is my attempt(following https://www.mathworks.com/matlabcentral/answers/194554-how-can-i-use-and-display-two-different-colormaps-on-the-same-figure):
function ButtonPushed(app, event)
x=randn(1000,1);
y=randn(1000,1);
ax1 = app.UIAxes;
histogram2(ax1,x,y,linspace(-3,3,30),linspace(-3,3,30),'DisplayStyle','tile')
hold (ax1,"on")
ax2 = app.UIAxes;
scatter(ax2,x,y,10,x.^2 + y.^2, 'filled')
hold (ax2,"off")
linkprop([ax1,ax2],'CLim');
ax2.XTick = [];
ax2.YTick = [];
colormap(ax1,'hot')
colormap(ax2,'spring')
cb1 = colorbar(ax1, "westoutside");
cb2 = colorbar(ax2, "eastoutside");
cb1.Label.String = 'histogram';
cb2.Label.String = 'scatter';
cb1.Label.FontSize = 12;
cb2.Label.FontSize = 12;
end
However, it seems like not giving the correct colorbars. I attheched the output below. Your help will be appreciated.

Réponse acceptée

Voss
Voss le 21 Juil 2023
Note that ax1 and ax2 are the same axes:
ax1 = app.UIAxes;
% ...
ax2 = app.UIAxes;
You won't be able to have multiple colormaps in one axes, but you can make a second axes, invisible and overlaying the first.
Something like this would work:
x=randn(1000,1);
y=randn(1000,1);
f = uifigure('Position',[50 50 1000 500]);
ax1 = uiaxes(f,'Units','normalized','Position',[0.15 0.1 0.7 0.8],'Box','on');
ax2 = uiaxes(f,'Units','normalized','Position',[0.15 0.1 0.7 0.8],'Visible','off');
histogram2(ax1,x,y,linspace(-3,3,30),linspace(-3,3,30),'DisplayStyle','tile')
scatter(ax2,x,y,10,x.^2 + y.^2, 'filled')
linkprop([ax1,ax2],{'CLim','XLim','YLim','Position'});
ax1.XTick = [];
ax1.YTick = [];
colormap(ax1,'hot')
colormap(ax2,'spring')
cb1 = colorbar(ax1, "westoutside");
cb2 = colorbar(ax2, "eastoutside");
cb1.Label.String = 'histogram';
cb2.Label.String = 'scatter';
cb1.Label.FontSize = 12;
cb2.Label.FontSize = 12;
  3 commentaires
Voss
Voss le 21 Juil 2023
Try the modified version attached.
Moslem Uddin
Moslem Uddin le 21 Juil 2023
Modifié(e) : Moslem Uddin le 21 Juil 2023
Thanks. That's working. Only issues I noticed so far is that sometime plots moving outside the box as like below:

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Red 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