Problem in reporting contour plot mathematica

Click For Summary

Discussion Overview

The discussion revolves around creating contour plots in Mathematica, specifically focusing on how to add color legends to these plots. Participants explore various methods for implementing legends, addressing issues related to version compatibility and the estimation of value ranges for color data.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant seeks assistance in adding a color legend to a contour plot generated in Mathematica, providing their code as context.
  • Another participant suggests using the "ShowLegend" function and provides an example, but does not clarify how to determine the range for color data.
  • A later reply questions how to estimate the range for color data, expressing uncertainty about the values used in the example.
  • Some participants mention the use of "PlotLegends -> Automatic" to allow Mathematica to determine the legend automatically, but there is confusion regarding its compatibility with different versions of Mathematica.
  • One participant notes that they are using an older version of Mathematica (version 7) and encounters an error when trying to use the "PlotLegends" option, indicating a potential compatibility issue.
  • Another participant emphasizes the importance of mentioning software versions when asking questions to facilitate better assistance and suggests using functions to estimate minimum and maximum values for defining legend bounds.

Areas of Agreement / Disagreement

Participants express differing views on how to implement color legends in contour plots, with some suggesting specific methods while others highlight version-related limitations. The discussion remains unresolved regarding the best approach for users of older software versions.

Contextual Notes

Limitations include the lack of clarity on how to estimate the range of values for color data and the potential incompatibility of certain functions with older versions of Mathematica.

quin
Messages
50
Reaction score
0
Dear friends
I plot a Contour plot from a function with mathematica, but I don't 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}]
 
Physics news on Phys.org
The answer to this question is the first result from a google search query. Please, do your homework.
Reference

Code:
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
 
thank you but how you can understand that you must put 1 to -1 for that range? I don't Know how to estimate the range of color data?

thanks a lot
 
Well, I haven't estimated it also, just did it as an example. Do a little research :)
 
how can I put "PlotLegends -> Automatic" in CountorPlot?
I search google but I couldn't 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
 
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:
  • Like
Likes   Reactions: 1 person
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.
 
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?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K