Mathematica Color Contour Plots for Varying Gamma Values in a Simple Equation

  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Color Plots
AI Thread Summary
The discussion focuses on creating contour plots in Mathematica with different colors for each value of gamma (γ). The user provides a function definition for f(γ, kΔx, σ) and demonstrates how to generate contour plots for various gamma values, specifying distinct colors for each plot using the ContourStyle option. They reference the Wolfram Language documentation for ColorFunction as a potential resource for further customization. The user expresses a desire for a more efficient method to achieve this but shares their current approach with detailed code examples.
member 428835
Hi PF!

I'm wondering if anyone knows how to make each plot for ##\gamma## a different color. What I have so far is
Code:
\[Gamma] = {0.01, 0.05, 0.1, 0.5, 1, 2};
ContourPlot[(1 + 2 \[Gamma]) \[Sigma]^2 +
   4 \[Gamma] Cos[k\[CapitalDelta]x] \[Sigma] - (1 - 2 \[Gamma]) ==
  0, {k\[CapitalDelta]x, 0, \[Pi]}, {\[Sigma], -1, 1},
 FrameLabel -> {"k\[CapitalDelta]x", "\[Sigma]"}]
 
Physics news on Phys.org
I don't know a neat way to condense it, but you can do it "by hand" using
Code:
f[\[Gamma]_,
  k\[CapitalDelta]x_, \[Sigma]_] := (1 + 2 \[Gamma]) \[Sigma]^2 +
  4 \[Gamma] Cos[k\[CapitalDelta]x] \[Sigma] - (1 - 2 \[Gamma])

Show[ContourPlot[
  f[0.01, k\[CapitalDelta]x, \[Sigma]] == 0, {k\[CapitalDelta]x,
   0, \[Pi]}, {\[Sigma], -1, 1},
  FrameLabel -> {"k\[CapitalDelta]x", "\[Sigma]"},
  ContourStyle -> Black],
ContourPlot[
  f[0.05, k\[CapitalDelta]x, \[Sigma]] == 0, {k\[CapitalDelta]x,
   0, \[Pi]}, {\[Sigma], -1, 1},
  FrameLabel -> {"k\[CapitalDelta]x", "\[Sigma]"},
  ContourStyle -> Orange],
ContourPlot[
  f[0.1, k\[CapitalDelta]x, \[Sigma]] == 0, {k\[CapitalDelta]x,
   0, \[Pi]}, {\[Sigma], -1, 1},
  FrameLabel -> {"k\[CapitalDelta]x", "\[Sigma]"},
  ContourStyle -> Green],
ContourPlot[
  f[0.5, k\[CapitalDelta]x, \[Sigma]] == 0, {k\[CapitalDelta]x,
   0, \[Pi]}, {\[Sigma], -1, 1},
  FrameLabel -> {"k\[CapitalDelta]x", "\[Sigma]"},
  ContourStyle -> Yellow],
ContourPlot[
  f[1, k\[CapitalDelta]x, \[Sigma]] == 0, {k\[CapitalDelta]x,
   0, \[Pi]}, {\[Sigma], -1, 1},
  FrameLabel -> {"k\[CapitalDelta]x", "\[Sigma]"},
  ContourStyle -> Red],
ContourPlot[
  f[2, k\[CapitalDelta]x, \[Sigma]] == 0, {k\[CapitalDelta]x,
   0, \[Pi]}, {\[Sigma], -1, 1},
  FrameLabel -> {"k\[CapitalDelta]x", "\[Sigma]"},
  ContourStyle -> Blue]]
 
Thank you both; I'll post if I find a quicker way.
 

Similar threads

Replies
1
Views
2K
Replies
1
Views
2K
Replies
6
Views
7K
Replies
5
Views
2K
Replies
8
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
7
Views
4K
Back
Top