连接散点图的点并创建一条线

发布于 2024-08-21 07:50:06 字数 31 浏览 6 评论 0 原文

绘图后如何连接散点图的点,并从点状图绘制一条线?

How is possible to join dots of a scatter plot after plotting, and make a line from a dotted plot?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

泪是无色的血 2024-08-28 07:50:06

我猜您从 xy 坐标生成了一个散点图,通过以下方式

plot(x,y,'.');

将它们连接起来

plot(x,y,'.');
hold on;
plot(x,y,'-');

Or 在一个命令中

plot(x,y,'.-');

这是您想要的吗?

I'm guessing you generated a scatter plot from x and y coordinates by,

plot(x,y,'.');

Join them with

plot(x,y,'.');
hold on;
plot(x,y,'-');

Or in one command

plot(x,y,'.-');

Is this what you wanted?

策马西风 2024-08-28 07:50:06

如果您有一个现有的散点图,则您不能简单地连接这些点而不知道哪些点与其他点相连。

如果您知道点的顺序/连接性,那么您可以首先使用绘图函数来完成此操作。该调用

plot(x,y,'-')

将用直线段连接这些点。如果您希望沿线的每个点使用标记符号,则可以添加绘图允许的标记之一,如下所示:

plot(x,y,'o-')

则可以从以下位置获取允许的标记列表

help plot

如果您在一组点上使用了散点图, ,现在希望覆盖一条连接点的线,然后使用hold函数强制matlab在散点图的顶部绘制。例如,

scatter(x,y)
hold on
plot(x,y,'-')
hold off

同样,任何这些变化都要求您了解点之间的连接性。有一些方案有时可以从孤立点列表中恢复连接。其中一种方法称为 CRUST,通常用于 3- d 表面重建。我通过简单搜索“外壳算法”找到了很多参考资料。

If you have an existing plot as a scatter plot, you cannot simply just join the dots without knowing which points are connected to which others.

If you know the order/connectivity of the points, then you could simply have used the plot function to do that in the first place. The call

plot(x,y,'-')

will connect the dots with straight line segments. If you wish to use a marker symbol at each point along the line, then you can add one of the markers that plot allows, as this:

plot(x,y,'o-')

You can get a list of the allowed markers from

help plot

If you have used scatter on a set of points, and now wish to overlay a line connecting the points, then use the hold function to force matlab to plot on top of the scatter plot. For example,

scatter(x,y)
hold on
plot(x,y,'-')
hold off

Again, any of these variations require you to know the connectivity between the points. There are some schemes that can sometimes work to recover that connectivity from a list of isolated points. One of these methods is called CRUST, often used for 3-d surface reconstruction. I found many references by a simple search for "crust algorithm".

时光磨忆 2024-08-28 07:50:06

如果您有一个散点图(我怀疑是用散点函数制作的)并且由于某种原因不想用绘图重新绘制它,那么您可以执行以下操作来连接这些点:

h = findobj(gca,'type','hggroup');
hold on
for k=1:numel(h)
    x = get(h(k),'xdata');
    y = get(h(k),'ydata');
    plot(x,y,'-')
end
hold off

这些点将按其原始顺序连接。如果需要,可以在绘图之前对数据进行排序,例如按 x:

[x,ind] = sort(x);
y = y(ind);

If you have a scatterplot (made with the scatter function I suspect) and for some reason don't want to redraw it with plot, here is what you can do to connect the dots:

h = findobj(gca,'type','hggroup');
hold on
for k=1:numel(h)
    x = get(h(k),'xdata');
    y = get(h(k),'ydata');
    plot(x,y,'-')
end
hold off

The dots will be connected by their original order. If you want you can sort the data before plot, for example by x:

[x,ind] = sort(x);
y = y(ind);
污味仙女 2024-08-28 07:50:06

要回答如何在 Maple 中执行此操作的问题,您只需使用 统计 的“nofollow noreferrer">PointPlot 命令将 style 选项设置为 linepointline 的包。例如:

Statistics:-PointPlot([2, 4, 6, 4], xcoords=[1, 2, 3, 4], style=pointline);

指定选项 style = pointline 显示点和连接线; style = line 仅显示线条。

To answer the question of how to do this in Maple, you can simply use the PointPlot command from the Statistics package with the style option set to line or pointline. For example:

Statistics:-PointPlot([2, 4, 6, 4], xcoords=[1, 2, 3, 4], style=pointline);

Specifying the option style = pointline shows both the points and a connecting line; style = line shows just the line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文