1
$\begingroup$

How can I extract a single contour line of a ListContourPlot?

Below is a minimal example:

ListContourPlot[Table[{x=RandomReal[{-2,2}],y=RandomReal[{-2,2}],Sin[x y]},{1000}]
    ,Contours->6
    ,MeshFunctions->{#3&},Mesh->{{0.5}},MeshStyle->Directive[Opacity[1,Red],Thick]
    ,PlotLegends->Automatic]

enter image description here

I'd like to get the red contour line at z = 0.5 (as an example) of different ListContourPlots and stack them in a new coordinate grid using Show.

$\endgroup$

closed as off-topic by march, corey979, José Antonio Díaz Navas, m_goldberg, Henrik Schumacher Oct 20 '18 at 7:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – march, corey979, José Antonio Díaz Navas, m_goldberg, Henrik Schumacher
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    $\begingroup$ Why not use the settings Contours -> {0.5}, ContourShading -> None? $\endgroup$ – J. M. will be back soon Oct 18 '18 at 15:40
  • $\begingroup$ Works perfectly, thanks. Sometimes, I seem to think too complicated... $\endgroup$ – DPF Oct 18 '18 at 16:08
  • $\begingroup$ @J.M.iscomputer-less can you post it as an answer, such that this can be flagged as solved by @DPF? $\endgroup$ – Gladaed Oct 19 '18 at 12:52
  • $\begingroup$ @Glad, not at a computer now, and this is a question that needs a picture as part of the answer. Maybe you or the OP can write one on my behalf? $\endgroup$ – J. M. will be back soon Oct 19 '18 at 13:08
  • $\begingroup$ @J.M.iscomputer-less did that, any comments? $\endgroup$ – Gladaed Oct 19 '18 at 13:28
3
$\begingroup$

You can use contours and contourStyles to specify thresholds and colors.

contours = {0.2, 0.5, 0.9}
contourStyles = {Red, Green, Blue}
ListContourPlot[
 Table[{x = RandomReal[{-2, 2}], y = RandomReal[{-2, 2}], 
  Sin[x y]}, {1000}], 
 Contours -> contours, 
 ContourStyle -> contourStyles, 
 ContourShading -> None, 
 MeshFunctions -> {#3 &}, 
 PlotLegends -> Automatic]

Multi-Threshold ContourPlot

You could combine them using Show like:

plots = ListContourPlot[
 Table[{x = RandomReal[{-2, 2}], y = RandomReal[{-2, 2}], 
  Sin[x y]}, {1000}], 
 Contours -> {contours[[#]]}, 
 ContourStyle -> {contourStyles[[#]]}, 
 ContourShading -> None, 
 MeshFunctions -> {#3 &}, 
 PlotLegends -> Automatic] & /@ Range[3]
Show[plots]

to generate them separated and combine them later.

$\endgroup$
  • 1
    $\begingroup$ Well-done! :) ${}$ $\endgroup$ – J. M. will be back soon Oct 19 '18 at 13:30
  • $\begingroup$ Especially the second part is what I wanted. The application is the comparison of the same contour heigths between different measurements of a 2D set point field. $\endgroup$ – DPF Oct 19 '18 at 15:44

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