Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem in reporting contour plot mathematica

  1. Sep 6, 2013 #1
    Dear friends
    I plot a Contour plot from a function with mathematica, but I dont know how can I add a small box near my figure that explain which value refer to which color?
    I put my code below, please help me with adding colordata to my code for having reference for colors.


    t = 0.01;

    m = 0.7820;

    ContourPlot[(3 (2 + m t (4 + m t)) - 4 (1 + m t) Cos[\[Pi] x] -
    2 Cos[2 \[Pi] x] - 4 (1 + m t) Cos[\[Pi] y] - 2 Cos[2 \[Pi] y] +
    4 Cos[\[Pi] (-x + y)] - 4 (1 + m t) Cos[\[Pi] (x + y)] -
    2 Cos[2 \[Pi] (x + y)] + 4 Cos[\[Pi] (2 x + y)] +
    4 Cos[\[Pi] (x + 2 y)])/(m (6 + m t (6 + m t) -
    2 Cos[2 \[Pi] x] - 2 Cos[2 \[Pi] y] -
    2 Cos[2 \[Pi] (x + y)])), {x, 0, 2}, {y, 0, 2}]
     
  2. jcsd
  3. Sep 6, 2013 #2
    The answer to this question is the first result from a google search query. Please, do your homework.
    Reference

    Code (Text):

    Needs["PlotLegends`"]
    ShowLegend[
     ContourPlot[(3 (2 + m t (4 + m t)) - 4 (1 + m t) Cos[\[Pi] x] -
         2 Cos[2 \[Pi] x] - 4 (1 + m t) Cos[\[Pi] y] - 2 Cos[2 \[Pi] y] +
         4 Cos[\[Pi] (-x + y)] - 4 (1 + m t) Cos[\[Pi] (x + y)] -
         2 Cos[2 \[Pi] (x + y)] + 4 Cos[\[Pi] (2 x + y)] +
         4 Cos[\[Pi] (x + 2 y)])/(m (6 + m t (6 + m t) -
           2 Cos[2 \[Pi] x] - 2 Cos[2 \[Pi] y] -
           2 Cos[2 \[Pi] (x + y)])), {x, 0, 2}, {y, 0,
       2}], {ColorData["LakeColors"][1 - #1] &, 10, " 1", "-1"}]
     
    d6dCG2G.png
     
  4. Sep 6, 2013 #3
    thank you but how you can understand that you must put 1 to -1 for that range? I dont Know how to estimate the range of color data?

    thanks alot
     
  5. Sep 6, 2013 #4
    Well, I haven't estimated it also, just did it as an example. Do a little research :)
     
  6. Sep 6, 2013 #5
    how can I put "PlotLegends -> Automatic" in CountorPlot?
    I search google but I couldnt find anything suitable for the above code ! Iwant mathematica to find plotlegend in an automatic way, not by writing for example 1 to -1

    thanks
     
  7. Sep 6, 2013 #6
    In[1]:= t = 0.01;
    m = 0.7820;
    ContourPlot[(3 (2 + m t (4 + m t)) - 4 (1 + m t) Cos[\[Pi] x] -
    2 Cos[2 \[Pi] x] - 4 (1 + m t) Cos[\[Pi] y] - 2 Cos[2 \[Pi] y] +
    4 Cos[\[Pi] (-x + y)] - 4 (1 + m t) Cos[\[Pi] (x + y)] -
    2 Cos[2 \[Pi] (x + y)] + 4 Cos[\[Pi] (2 x + y)] +
    4 Cos[\[Pi] (x + 2 y)])/(m (6 + m t (6 + m t) -
    2 Cos[2 \[Pi] x] - 2 Cos[2 \[Pi] y] -
    2 Cos[2 \[Pi] (x + y)])), {x, 0, 2}, {y, 0, 2},
    PlotLegends -> Automatic]

    Out[3]= ...PlotWithLegendSnipped...

    works for me, at least for this example in version 9.

    As for being unable to find anything on this, if you Google
    Mathematica ContourPlot
    the first result is
    http://reference.wolfram.com/mathematica/ref/ContourPlot.html
    and if you click on Details and Options near the top of that you
    see the minimal documentation on the PlotLegends option.
    Or you can get the identical information from your Mma help pages.
    Values that may be given with Options are unfortunately often
    inadequately documented, but this one is better than most.
     
    Last edited: Sep 6, 2013
  8. Sep 6, 2013 #7
    thanks but I have mathematica 7 and when I type that code, it gives error that unknown plotlegends in contourplot ! however, I write : needs"plotlegends'" too.
     
  9. Sep 7, 2013 #8
    If anyone is not using the current version of software then it would be really helpful if they made sure to explain that when they ask their question. That will allow people to see if they can think of any workarounds that would be backward compatible with your version when they try to give answers.

    What if you use one of the available functions to estimate the minimum and maximum values that your function has inside the plot range you are going to display and use those values to define the upper and lower bounds of your PlotLegends?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook