Filter löschen
Filter löschen

adding two colorbars in the uiaxes of app designer matlab

8 Ansichten (letzte 30 Tage)
Moslem Uddin
Moslem Uddin am 21 Jul. 2023
Bearbeitet: Moslem Uddin am 21 Jul. 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.

Akzeptierte Antwort

Voss
Voss am 21 Jul. 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 Kommentare
Voss
Voss am 21 Jul. 2023
Try the modified version attached.
Moslem Uddin
Moslem Uddin am 21 Jul. 2023
Bearbeitet: Moslem Uddin am 21 Jul. 2023
Thanks. That's working. Only issues I noticed so far is that sometime plots moving outside the box as like below:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by