1
$\begingroup$

Let's say we have a contour plot of the following,

ContourPlot[Cos[x] + Cos[y], {x, 0, Pi}, {y, 0, Pi}, 
ContourLabels -> True]

that gives,

enter image description here

we can extract the line objects and points associated with those lines as

Cases[Normal@%, Line[pts_] -> pts, Infinity]

ListLinePlot@%

which looks like in the following,

enter image description here

so, is there any way I can replace the line points, which are infact z slices with a user-defined function Sin[z]? so it will be Sin[-1.5],Sin[-1] and so on

and plot the contour plot again.

so extraction of data from the contour plot and changing it with a user-defined function

$\endgroup$
4
  • $\begingroup$ Is z the contourvalue? $\endgroup$ Feb 28, 2023 at 12:40
  • $\begingroup$ @Ulrich Neumann yes! $\endgroup$
    – a019
    Feb 28, 2023 at 12:52
  • $\begingroup$ Just to be clear, are you trying to rescale the contours lines? So rather than the contour lines indicating points where the amplitude z = 1.5 for example, you prefer it to instead show points where the amplitude is Sin[1.5]? $\endgroup$
    – alex
    Feb 28, 2023 at 13:03
  • $\begingroup$ @alex Yes, rescaling z=1.5 with a function Sin[z] or Sin[1.5], so kind of replacing as well. $\endgroup$
    – a019
    Feb 28, 2023 at 13:04

2 Answers 2

3
$\begingroup$

Try

plot = ContourPlot[Cos[x] + Cos[y], {x, 0, Pi}, {y, 0, Pi} ]

detect contourlines and values

list = Cases[Normal@plot, Tooltip[{__, a__Line }, b_] :> {b, a  },Infinity];

create new points Sin[conourvalue]

p3D = Flatten[
Table[Map[Join[#, {Sin[list[[i, 1]]]}] &, list[[i, 2]][[1 ]]], {i,Length[list]}] , 1] 
ListPlot3D[p3D, MeshFunctions -> {#3 &}]

enter image description here

$\endgroup$
2
  • $\begingroup$ can we plot p3D in 2D contourplot rather than in Graphics3D? $\endgroup$
    – a019
    Feb 28, 2023 at 13:18
  • 1
    $\begingroup$ @a019 I modified my answer $\endgroup$ Feb 28, 2023 at 13:21
2
$\begingroup$

Manipulating the list as shown by @Ulrich is what one would do to simply rescale.

For the sake of completion, I'm also adding the option in case you wanted to know the contour points for a specified function. You can achieve this using ContourPlot3D:

ContourPlot3D[
 Cos[x] + Cos[y] == Sin[z], {x, 0, Pi}, {y, 0, Pi}, {z, -2, 2}]

enter image description here

You of course recover your default answers by leaving the equation unspecified:

ContourPlot3D[Cos[x] + Cos[y], {x, 0, Pi}, {y, 0, Pi}, {z, -2, 2}, 
 Contours -> 11]

enter image description here

Best of luck.

$\endgroup$

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.