필터 지우기
필터 지우기

adding two colorbars in the uiaxes of app designer matlab

조회 수: 8 (최근 30일)
Moslem Uddin
Moslem Uddin 2023년 7월 21일
편집: Moslem Uddin 2023년 7월 21일
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.

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by