gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:09:24 25 4
gpt4 key购买 nike

我有一个三维密度分布并创建一个包含两个子图的图形。 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com