1
$\begingroup$

I have some data that I am plotting with ListContourPlot and I would like my contours to be closed at the edge (closing around the high value region).

A simple example:

ListContourPlot[{{3, 2, 1, 0}, {2, 1, 1, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}},
                 Contours -> {1}, ContourShading -> None, ContourStyle -> Thick]

![plot of unclosed contours](http://i.imgur.com/B8eMa5d.png)

I know you can add e.g. BoundaryStyle -> Black, but it closes the whole region:

enter image description here

Note that I have tried the answer here, but that method changes the plotting method from plotting a matrix to plotting {x,y,f(x,y)} values, which has some undesirable results on my (much more complicated than the above example) data.

$\endgroup$
4
  • $\begingroup$ So your desired result is something like: ListContourPlot[{{3, 2, 1, 0}, {2, 1, 1, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}}, Contours -> {1}, ContourShading -> None] /. Line[x_] :> Line[Join[{{1, 1}}, x, {{1, 1}}]] ? $\endgroup$
    – Kuba
    Mar 21, 2014 at 20:24
  • $\begingroup$ Yes it is, but generalised $\endgroup$
    – Jay
    Mar 21, 2014 at 20:34
  • $\begingroup$ I'm not sure what you mean, in the above example the lower leftmost point has a value of 3 - it is the 'summit'. I want to close the contour around this summit, even though it is on the edge of the matrix. $\endgroup$
    – Jay
    Mar 21, 2014 at 20:48
  • $\begingroup$ Ok, I see your point. Let me provide an answer and we will se if it fits your needs. $\endgroup$
    – Kuba
    Mar 21, 2014 at 20:57

1 Answer 1

1
$\begingroup$

You can pad your array of points with value much below the lowest one, like that:

data = {{3, 2, 1, 0}, {2, 1, 1, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}};
data = ArrayPad[data, 1, -10^6]

ListContourPlot[data, Contours -> {1}, ContourShading -> None, ContourStyle -> Thick,
                      DataRange -> {{0, 5}, {0, 5}}]

enter image description here

I've also added DataRange so it fits primordial data set.

$\endgroup$
2
  • $\begingroup$ Thanks, this will do the trick. $\endgroup$
    – Jay
    Mar 21, 2014 at 21:11
  • $\begingroup$ @Jay Great, good luck :) $\endgroup$
    – Kuba
    Mar 21, 2014 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.