LoginSignup
2
5

More than 3 years have passed since last update.

MATLABの複数subplotで共通するcolorbarの追加方法

Last updated at Posted at 2020-06-29

二次元プロットの場合、表現できるデータの種類はx軸、y軸と色を使った最大三種類。
三次元プロットならz軸も併せ四種類。兎に角、MATLABのplot内でcolorbarの追加についてメモ。

単一プロットの場合

例えば、複数の軌道をひとつのプロットにまとめて表したいとする。

colorSet = cool(length(family));

for i = 1:100:length(family)
    [~, ~, ~, X_out] = integrate_er3bp_ode45_stm(family(i,1).state, family(i,1).period, mu, 0);
    figure(5)
    plot3(X_out(1,:), X_out(2,:), X_out(3,:),'-', 'linewidth', 0.7, 'Color', colorSet(i,:));
end
set(gcf, 'Colormap', colorSet);
caxis([family(1,1).period, family(end,1).period]);
colorbar('eastoutside');

上記のcolorbar()関数内でバーの場所を指定。オプションはdocsを参照:
https://uk.mathworks.com/help/matlab/ref/colorbar.html

halo_color.png

Subplotのスタック方向にcolorbarを追加する

これはどうも苦戦中… これから脱却したい…
image.png

Subplotのスタックの隣にcolorbarを追加する

https://stackoverflow.com/questions/10649286/how-to-keep-the-subplot-sizes-unchanged-after-putting-a-colorbar
より

f1=figure(1);clf;
s1=subplot(1,2,1);
surf(peaks(20));

s2=subplot(1,2,2);
surf(peaks(20));
hb = colorbar('location','eastoutside');

%% # Solution:
s1Pos = get(s1,'position');
s2Pos = get(s2,'position');
s2Pos(3:4) = [s1Pos(3:4)];
set(s2,'position',s2Pos);

https://stackoverflow.com/questions/10649286/how-to-keep-the-subplot-sizes-unchanged-after-putting-a-colorbar
https://stackoverflow.com/questions/16064451/reposition-colorbar-or-subplots

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5