フィルターのクリア

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 Center および File ExchangeRed についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by