I have the following DensityPlot:

DensityPlot[Sin[x] Sin[y], {x, -Pi/4, Pi/4}, {y, -Pi/4, Pi/4}, ColorFunction -> "SunsetColors", PlotLegends -> Automatic]

enter image description here

Now I want to see only the values of density along the function "y = 1/2 (ArcCos[1 - Cos[2 x]])". I had the idea to use a KroneckerDelta as following but it does not work !

X[x_, y_] = KroneckerDelta[1/2 (ArcCos[1 - Cos[2 x]]), y]

DensityPlot[Sin[x] Sin[y]*X[x, y], {x, -Pi/4, Pi/4}, {y, -Pi/4, Pi/4},ColorFunction -> "SunsetColors", PlotLegends -> Automatic]

enter image description here

Any idea why this is not working and how to rectify ?

Thank you for your time !


  • $\begingroup$ DensityPlot is not meant to be used for drawing curves. $\endgroup$ – shrx Mar 27 '15 at 10:55
  • $\begingroup$ Since KroneckerDelta is in effect "infinitely thin," DensityPlot can't locate where it is nonzero. $\endgroup$ – 2012rcampion Mar 27 '15 at 13:20
  • $\begingroup$ Ok I understand the problem ! $\endgroup$ – Geoff Hudson Mar 27 '15 at 17:26

If you want a curve whose shape is determined by y = 1/2 (ArcCos[1 - Cos[2 x]]) and whose color is determined by Sin[x] Sin[y], you may use

Plot[1/2 (ArcCos[1 - Cos[2 x]]), {x, -\[Pi]/4, \[Pi]/4}, 
ColorFunction -> Function[{x, y}, ColorData["SunsetColors"][Sin[x] Sin[y]]]]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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