フィルターのクリア

How can I lock my repositioned colorbar to the rest of my figure?

4 ビュー (過去 30 日間)
aaron Harvey
aaron Harvey 2015 年 10 月 8 日
コメント済み: aaron Harvey 2015 年 10 月 8 日
Hi, I have produced a script to construct a contour plot with a colour bar within the plot itself. However when I change the size of the figure window the colour bar does not scale with it. Is there a way to get the colour bar to scale with the rest of the figure? Scipt:
function contf(A,B,C,D,E)
figure
a=min(A):(max(A)-min(A))/200:max(A);
b=min(B):(max(B)-min(B))/200:max(B);
[Aq,Bq]=meshgrid(a,b);
Z=griddata(A,B,D,Aq,Bq);
contourf(Aq,Bq,Z);
set(gca,'YDir','reverse');
set(gca,'xaxislocation','top');
xlabel('Distance upstream from Blackrock (m)');
ylabel('Depth(m)');
c=colorbar('southoutside');
c.Label.String=E;
set(c,'units','points','position',[450,52,150,15]);
axis([0,max(A),0,35]);
set(gcf,'units','points','position',[55,100,700,200]);
set(gca,'box','off');
hold on;
plot(A,C,'k');
hold off;
end

採用された回答

Adam
Adam 2015 年 10 月 8 日
set( c, 'units', 'normalized' )
after you have positioned it in points if that is your preferred method is the usual way to achieve a resizing object when the figure resizes, but it doesn't always yield the kind of resizing you want and I haven't tried it with colourbars.
Otherwise you may need to program a SizeChangedFcn callback for your figure in which you keep doing the new positioning maths yourself based on the current figure size or axes position or whatever you want to base it off.
Alternatively you could try the GUI Layout toolbox in the File Exchange, but that has a learning curve, especially for objects like colourbars.
  1 件のコメント
aaron Harvey
aaron Harvey 2015 年 10 月 8 日
Awesome! thank you. That worked a treat.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by