在绘图中的点周围绘制圆圈

May*_*ani 3 matlab plot border matlab-figure

我有两个矩阵

timeline =  [0.0008    0.0012    0.0016    0.0020    0.0024    0.0028];
Run Code Online (Sandbox Code Playgroud)

Origdata =

   79.8400   69.9390   50.0410   55.5082   34.5200   37.4486   31.4237   27.3532   23.2860   19.3039
   79.7600   69.8193   49.8822   55.3115   34.2800   37.1730   31.1044   26.9942   22.8876   18.9061
   79.6800   69.6996   49.7233   55.1148   34.0400   36.8975   30.7850   26.6352   22.4891   18.5084
   79.6000   69.5799   49.5645   54.9181   33.8000   36.6221   30.4657   26.2762   22.0907   18.1108
   79.5200   69.4602   49.4057   54.7215   33.5600   36.3467   30.1464   25.9173   21.6924   17.7133
   79.4400   69.3405   49.2469   54.5249   33.3200   36.0714   29.8271   25.5584   21.2941   17.3159
Run Code Online (Sandbox Code Playgroud)

当我绘制它们时,我会得到如下图.

plot(timeline, Origdata, '.');
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如何在每个点周围绘制一个半径为0.3524的圆?该半径应仅相对于y轴.

Sue*_*ver 5

您可以轻松地使用viscircles(这需要图像处理工具箱),但我不认为输出实际上是您所期望的.

radius = 0.3524;
dots = plot(timeline, Origdata, '.');

hold on

for k = 1:numel(dots)
    plotdata = get(dots(k));
    centers = [plotdata.XData(:), plotdata.YData(:)];

    % Ensure the the colors match the original plot
    color = get(dots(k), 'Color');

    viscircles(centers, radius * ones(size(centers(:,1))), 'Color', color);
end
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

看起来这是因为你的X数据相对于你的y数据非常接近,而圆圈显示为圆圈,我强迫轴的x和y比例相等(axis equal)

编辑

如果你只想要radius相对于y轴(距离),那么我们实际上需要绘制具有x和y半径的椭圆.我们希望缩放"x-radius"以使其显示为圆形而不管您的真实轴长宽比,这样的事情实际上可以做到这一点.

以下代码的技巧是将数据和绘图宽高比(pbaspectdaspect)设置为手动.这可确保在缩放,调整大小等过程中轴的纵横比不会发生变化,并确保我们的"圆圈"保持圆形外观.

dots = plot(timeline, Origdata, '.');

drawnow

% Force the aspect ratio to not change (keep the circles, as circles)
pbaspect('manual')
daspect('manual')

hold on

aspectRatio = daspect;

t = linspace(0, 2*pi, 100);
t(end+1) = NaN;

radius = 4.3524;

% Scale the radii for each axis
yradius = radius;
xradius = radius * aspectRatio(1)/aspectRatio(2);

% Create a circle "template" with a trailing NaN to disconnect consecutive circles
t = linspace(0, 2*pi, 100);
t(end+1) = NaN;
circle = [xradius*cos(t(:)), yradius*sin(t(:))];

for k = 1:numel(dots)
    x = get(dots(k), 'XData');
    y = get(dots(k), 'YData');
    color = get(dots(k), 'Color');

    % Center circle template at all points
    circles = arrayfun(@(x,y)bsxfun(@plus, [x,y], circle), x, y, 'uni', 0);
    circles = cat(1, circles{:});

    plot(circles(:,1), circles(:,2), 'Color', color)
end
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

只是为了证明,如果我们将圆半径增加到4.3524,我们可以更好地看到圆圈.

在此输入图像描述

这适用于所有调整大小等.

在此输入图像描述

  • 这个gif真的需要这么令人眼花缭乱吗?:-P (2认同)