How do I plot a smooth line from a scatter graph which is not a 1 to 1 graph

7 Ansichten (letzte 30 Tage)
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
Star Strider
Star Strider am 3 Jan. 2017
What are your data?
How did you measure or calculate them?
physicsn00b
physicsn00b am 3 Jan. 2017
Bearbeitet: physicsn00b am 3 Jan. 2017
I had a quartic with 2 parameters 'x' and 'y' (the ones in the plot), i solved for a range of x and a range of y, then took the difference between the each of the 4 solutions if that difference was close to this number that i chose then x and y would be plotted,
anyway i have a vector for the x values which is the independant variable in increasing order, some x values had more than one y value to go with it so that x value would be repeated in that vector, then the y vector was the dependant variable , i plotted these 2 vectors. Ive thought of splitting the 4 lines in the picture but i cant because the way i got the values was find all y for a certain x

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by