matlab - 颜色条高度太大并且重叠图形标题

标签 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])

最佳答案

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

关于matlab - 颜色条高度太大并且重叠图形标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31610068/

相关文章:

matlab - 绘制顶轴(框)线

matlab - 无法使用自定义字体导出matlab图形

matlab - 如何在 MATLAB 中通过 ROI 放大图像

Python Tkinter 崩溃,除了程序之外的每次运行都继续? Tkinter 的最终完善

matlab - MATLAB 标题的不同部分使用不同的颜色

matlab - 如何计算拉普拉斯掩模或任何尺寸

matlab - 使用 for 循环迭代空矩阵

matlab - 在 MATLAB 中从灰度图像进行圆检测

将十六进制 C 数组转换为 Matlab vector

matlab - 我应该怎么做才能不显示所有情节的图例?