Matlab长宽比问题

标签 matlab matlab-figure aspect-ratio

最近,我一直在使用 matlab 来运行粒子聚集模拟,并使用它的绘图 itnerface 来表示每个粒子。因此,我编写了一些代码来调整标记的大小,使其等于实际粒子的直径 - 与窗口的纵横比等相关。好吧,如果我处理的是方形域,这非常有效;见下文。

enter image description here

正如您所看到的,标记的大小使得粒子能够完美地沉淀在彼此的顶部。这是该图像的绘图代码:

%%Initial Plot at time t = 0 Along with Scaling in the Y-Direction
figure;    h=scatter(Pos(1,:),Pos(2,:),6,jet(length(Pos(1,:))),'filled','MarkerEdgeColor','k','linewidth',1);
hold on
axis equal
axis ([0 dp 0 dp]*L*Scale)
currentunits = get(gca,'Units');
set(gca, 'Units', 'Points');
axpos = get(gca,'Position');
set(gca, 'Units', currentunits);
markerWidth = dp/diff(ylim)*axpos(4); % Calculate Marker width in points
set(h, 'SizeData', markerWidth^2)

嗯,我在模拟中添加了周期性边界条件,这意味着我可以使用上面显示的 3 倍的窗口大小,而无需太多额外的计算成本。所以,我想绘制一个 3x1 域(x 基本上比域的 y 维度长 3 倍)。然而,我在适当调整粒子大小时遇到​​了麻烦,以便它们在 y 方向上正确缩放,同时也沿 x 方向接触。我想我可以使用某种纵横比代码来做到这一点,但我无法让它工作。有任何想法吗?这是我想出的代码/结果:

%Plot all of the data
figure;
h=scatter(Pos(1,:),Pos(2,:),6,jet(length(Pos(1,:))),'filled','MarkerEdgeColor','k','linewidth',1);
hold on
axis equal
axis ([0 3*dp 0 3*dp]*L*Scale)
currentunits = get(gca,'Units');
set(gca, 'Units', 'Points');
axpos = get(gca,'Position');
set(gca, 'Units', currentunits);
markerWidth = dp/diff(ylim)*axpos(4); % Calculate Marker width in points
set(h, 'SizeData', (markerWidth)^2)
axis ([0 3*dp 0 dp]*L*Scale)

它产生以下结果,这显然是不正确的:(... enter image description here

最佳答案

你可以使用类似的东西

%cirlce def
circx = sin(linspace(0,2*pi,100));
circy = cos(linspace(0,2*pi,100));

%example data
[mgx mgy] = meshgrid(5:5:100, 5:5:100);
x = reshape(mgx,[],1); %circles centers x
y = reshape(mgy,[],1); %circles centers x
r = 2.5*rand(400,1);   %radii
c = 250*rand(400,1);   %colors

% draw
figure
hold on
for i=1:numel(x)
  fill(r(i)*circx+x(i), r(i)*circy+y(i), c(i))
end

使所有几何数据都固定在坐标轴空间中。 示例输出为:

Example result

关于Matlab长宽比问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25856817/

相关文章:

matlab - 带动画的实时脚本

强制 HTML 元素的纵横比的 Javascript 库?

html - CSS 高度等于宽度

matlab - 如何做气泡图?

matlab - 如何对时间序列数据执行 K 均值聚类?

matlab - 尝试/捕获并使用空字符串错误

matlab - 以用户在 MATLAB 中测量的指定角度始终如一地生成线

matlab - 如何在 MATLAB 中将坐标区对象放置在图形顶部?

CSS保持纵横比不起作用

matlab - 在Matlab中加载LibSVM的模型文件