How do I plot a smooth line from a scatter graph which is not a 1 to 1 graph
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I currently have this scatter plot

how do I plot smooth lines through the points? when I use plot(x,y,'-') the lines go from one point to the point with the next x value, the lines zig zag up and down, i dont want this i want smooth lines where they should go thanks!
2 Kommentare
Antworten (1)
Walter Roberson
am 4 Jan. 2017
First, sort your points by x value.
Then, create a KDTree object with the data, and do a rangesearch of all points within a radius, specifying each point as the query point Y. Specify 'Distance', 'seuclidean' and specify a 'Scale' argument to take into account your X scale is roughly 10 times bigger than your Y scale. You want to tune your radius so that the lowest arc and the second lowest arc are not considered to be close enough at roughly x == pi. That might lead to gaps in the arc such as the top arc near x = pi/2; there is no rule that says you cannot have more than 4 arcs.
Now, if you have set your tolerance appropriately, all points will have show up as having several neighbours within range.
For each point, proceed through the list of its near neighbours. Because of the earlier sorting, the list should (I think) already be sorted by x values. But check how the y values proceed. If diff() of the y values is either all positive or all negative, then you have a simple connection situation, and you should mark the point as being connected to the point before it and the point after it in the x order.
If diff() of the y values is mixed positive and negative, then you are in the area of an intersection between the arcs. At the moment I am not sure of the best way to handle that. It might be possible to divide the data into two subsets, one decreasing and one increasing, that would tell you something about the continuity of the neighbouring points, but it is not clear which you should connect the current point to, as ideally you would prefer to have only one point as being "the" intersection point, so some kind of region algorithm might be called for.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!