Closed mgr327 closed 8 years ago
As you'll note, length(c.lines) == 2
. You'll get the other branch if you do xs2, ys2 = coordinates(c.lines[2])
and plot them too :)
More generally, contour lines will be traced either in loops or reaching the domain boundaries, and each continuous curve will be returned as a separate Curve2
object in c.lines
.
Plotting this example again (with Gadfly
this time, since I don't have matplotlib
on this computer):
x = -3:0.01:3
y = -3:0.01:3
z = [Float64((xi^2 - yi^2)) for xi in x, yi in y];
h = 2
using Contour
c = contour(x,y,z,h)
using Gadfly
plot([layer(x=xs,y=ys,Geom.path) for (xs,ys) in map(coordinates, c.lines)]...)
shows both branches.
(If you want to use Gadfly for plotting, this is built-in there, so you don't have to worry about the Contour package at all if plotting is all you want to do.)
Thank you!
It is probably going to benefit everyone if you add your example to the readme.md file of the package.
When a contour consist of several disconnected branches, only one branch is found. The following example illustrates the problem:
using PyPlot, Contour
x = -3:0.01:3
y = -3:0.01:3
z = [Float64((xi^2 - yi^2)) for xi in x, yi in y];
h = 2
c = Contour.contour(x, y, z, h); # both Contour and PyPlot have contour()
xs, ys = coordinates(c.lines[1]);
plot(xs, ys)
The result is one branch, whereas there must be two disconnected ones
The version of Contour from github was used on Julia 0.4.3
versioninfo() Julia Version 0.4.3 Commit a2f713d* (2016-01-12 21:37 UTC) Platform Info: System: Linux (x86_64-redhat-linux) CPU: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz WORD_SIZE: 64 BLAS: libopenblas (DYNAMIC_ARCH NO_AFFINITY Sandybridge) LAPACK: libopenblasp.so.0 LIBM: libopenlibm LLVM: libLLVM-3.3