颜色条高度太大,图形标题重叠

Colorbar height is too large and overlapping figure title

我有一个 three-dimensional 密度分布,并创建了一个包含两个子图的图形。 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,''})

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

% 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])

这里有一个可能的解决方法,首先从每个切片获取颜色数据,然后使用 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