3
$\begingroup$
f[k_, α_, N_] := Sum[Sin[k*m/2]^2/m^(1 + α), {m, 1, N}]

ContourPlot[(f[k, 1, 1000] - 2 A^2) == 0, {k, -π, π}, {A, 0, 
  2}, FrameLabel -> {"k", "A"}, PlotLegends -> Automatic]

I want to shade the region above each of the two curves shown below using RegionPlot. To do this, I tried:

RegionPlot[(f[k, 1, 1000] - 2 A^2) < 0 , {k, -π, π}, {A, 0, 
  2}, FrameLabel -> {"k", "A"}, PlotLegends -> Automatic]

but this yields a region being shaded but does not have the "kink" part. Why?

enter image description here

enter image description here

$\endgroup$
1
  • $\begingroup$ PlotPoints -> 80, MaxRecursion -> 4 can improve the plot. $\endgroup$
    – cvgmt
    Aug 26, 2023 at 1:27

2 Answers 2

4
$\begingroup$

We can use ContourPlot to do this.

ContourPlot[(f[k, 1, 1000] - 2 A^2), {k, -π, π}, {A, 0, 2}, 
 FrameLabel -> {"k", "A"}, PlotLegends -> Automatic, Contours -> {0}, 
 ContourShading -> {{Opacity[.5], ColorData[97][1]}, None}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Could you please explain how it works? e.g, what does "Contours ->{0}" do? $\endgroup$
    – KZ-Spectra
    Aug 26, 2023 at 3:37
  • 1
    $\begingroup$ @KZ-Spectra We can read the Contours in Mathematica documents. reference.wolfram.com/language/ref/Contours.html Contous can set the level sets and ContourShading can shading the level sets. $\endgroup$
    – cvgmt
    Aug 26, 2023 at 3:43
2
$\begingroup$

Using ListContourPlot:

expr = f[k, 1, 1000] - 2 A^2;
sty = {Style["k", Black, 14], Style["A", Black, 14]};

ListContourPlot[Transpose@Table[expr, {k, -π, π, π/10}, {A, 0, 2, 0.05}],
Contours -> {0}, FrameLabel -> sty, LabelStyle -> Directive[Black, Medium], 
ColorFunction -> (If[# < 0, Darker[Blue, Abs[#]], Lighter[Cyan, #]] &), 
ContourStyle -> Directive[Darker[Blue], Thickness[0.0025]]]

enter image description here

$\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.