开发者

joining dots of a scatter plot and create a line

How is possible to join dots of a scatter plot after plotting,开发者_开发知识库 and make a line from a dotted plot?


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?


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".


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜