Re: Plot Joined Intelligently

*To*: mathgroup at smc.vnet.net*Subject*: [mg30517] Re: [mg30501] Plot Joined Intelligently*From*: Daniel Lichtblau <danl at wolfram.com>*Date*: Fri, 24 Aug 2001 20:58:11 -0400 (EDT)*References*: <200108240805.EAA26984@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hugh Goyder wrote: > > Dear Mathgroup, > > A list of {x, y} values supplied to ListPlot, with PlotJoined -> True, > sensibly joins the points in the order of the list. Sometimes I produce > points that lie on a set of smooth curves but do not produce the points in > any particular order. How can I join the points to form a line > intelligently, for example, joining each point to its nearest neighbour? > > An example. I solve for the roots of a polynomial with a parameter g that I > vary. I convert the complex values to {x,y} pairs. I then plot using > ListPlot which clearly shows that the roots lie along definite curves. How > can I join the points up to make the curves lines? > > data = {Re[#], Im[#]} & /@ Flatten[Table[s /. NSolve[s^10 + g^10 (1 + s) == > 0, s], {g, 0, 2, 0.05}]]; > > ListPlot[ data]; > > Thanks > > Hugh Goyder If the points come from, say, a multivalued algebraic function, it may be better to work directly with the multiple branches. One approach in that setting is to try to match up the (algebraic) functions at crossing points. Some ideas for how one might try to find crossing points are in a MathGroup post from a year ago, at the URL below. http://library.wolfram.com/mathgroup/archive/2000/Aug/msg00187.html Between crossings you can simply connect points that come from a particular piece of the solution set. At crossings in effect you connect pieces by matching up derivatives. If all you have is a set of points partitioned by common x values, you can simulate the above ideas as follows. (i) Assume we are at an x value, x[0] not "near" to a crossing. Then finding successor points to each {x[0],y[k,0]} pair is just a matter of finding, for each point at the next x-value (x[1]), the closest of the candidate y[1] values; it becomes y[k,1]. This assumes no crossing occurred in between, which in turn is an assumption that derivatives are not excessive. (ii) When you get to an x value for which some y values are "close", the appropriate connections are now obtained via derivative approximations. You want the least bend, so (y[k,n+1]-y[k,n])/(x[n+1]-x[n]) should most closely approximate (y[k,n]-y[k,n-1])/(x[n]-x[n-1]) in order to correctly extend the kth curve. Note that branches that "go complex" will cause trouble, as they join together at a vertical tangent at the crossings. Also an tangential crossing will be dificult to properly match. In fact, the method I show at the above URL will not even find such crossings. Daniel Lichtblau Wolfram Research

**References**:**Plot Joined Intelligently***From:*Hugh Goyder <goyder@rmcs.cranfield.ac.uk>

**Lines in a legend are too short**

**Re: Modified shooting method**

**Plot Joined Intelligently**

**Re: Plot Joined Intelligently**