adding two colorbars in the uiaxes of app designer matlab

8 次查看(过去 30 天)
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 个评论
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