Colorbar高度太大且图标重叠

时间:2015-07-24 12:02:06

标签: matlab matlab-figure figure colorbar

我有一个三维密度分布,并创建一个带有两个子图的图形。其中一个XY平面和一个YZ平面。对于这两个数字,我想要一个正确的colorbar,由于某种原因,XY平面colorbar是完美的,YZ平面colorbar太大而且与图标题重叠。请参阅下面的代码和结果图片。编辑:在底部添加功能示例

%// Data slice in the XY plane
    subplot(1,2,1)
    h=slice(xi,yi,zi,density,[],[],0);
    set(h,'edgecolor','none');
    caxis([-8,-2])
    colormap(jet);
    c = colorbar;
    c.Label.String = 'Density in log 10 scale';
    view(2)
    daspect([1 1 1])
    xlabel('X-axis [km]')
    ylabel('Y-axis [km]')
    zlabel('Z-axis [km]')
    title_orbit = ['Mg sputtering in orbital plane at orbit angle ',is];
    title({title_orbit,''})

%// Data slice in the YZ plane
    subplot(1,2,2)
    g=slice(xi,yi,zi,density,0,[],[]);
    set(g,'edgecolor','none');
    caxis([-8,-2])
    colormap(jet);
    d = colorbar;
    d.Label.String = 'Density in log 10 scale';
    view(90,0)
    daspect([1 1 1])
    xlabel('X-axis [km]')
    ylabel('Y-axis [km]')
    zlabel('Z-axis [km]')
    title_perp = ['Mg sputtering in perpendicular plane at orbit angle ',is];
    title({title_perp,''})

enter image description here

对于那些想要尝试修复它的工作示例的人,请参阅下面的代码。

% Create data with similar structure as original
x = linspace(-100,100,100);
y = linspace(-100,100,100);
z = linspace(-100,100,100);
[xg,yg,zg] = meshgrid(x,y,z);
density = rand([100,100,100]);

% Plot data
figure
subplot(1,2,1)
h=slice(xg,yg,zg,density,[],[],0);
set(h,'edgecolor','none');
colormap(jet);
c = colorbar;
view(2)
daspect([1 1 1])

subplot(1,2,2)
g=slice(xg,yg,zg,density,0,[],[]);
set(g,'edgecolor','none');
colormap(jet);
c = colorbar;
view(90,0)
daspect([1 1 1])

1 个答案:

答案 0 :(得分:1)

这是一种可行的解决方法,首先从每个切片中获取颜色数据,然后使用imagescimshow绘制切片数据。使用您的示例:

h=slice(xg,yg,zg,density,0,[],[]);
H=get(h,'CData');
...
g=slice(xg,yg,zg,density,0,[],[]);
G=get(g,'CData');
...

然后打开一个新图并使用imagescimshow

figure;
subplot(1,2,1)
imshow(H); colormap(jet); colorbar


subplot(1,2,2)
imshow(G); colormap(jet); colorbar

enter image description here