Problem in reporting contour plot mathematica

In summary: For example, the functioncontourplot[x_min, x_max, y_min, y_max, color_min, color_max]will estimate the values at the points (x_min, y_min) and (x_max, y_max) and return the string "ContourPlot[x_min, x_max, y_min, y_max, color_min, color_max]" that you can use as the value for the PlotLegends option in a CountorPlot. For a more complicated example, you could use a function that estimates the values at a series of points and returns a list of lists where each list contains the values at the points
  • #1
quin
50
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
  • #2
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
 
  • #3
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 alot
 
  • #4
Well, I haven't estimated it also, just did it as an example. Do a little research :)
 
  • #5
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
 
  • #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:
  • Like
Likes 1 person
  • #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.
 
  • #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?
 

1. What is a contour plot in Mathematica?

A contour plot in Mathematica is a two-dimensional graphical representation of a three-dimensional surface. It displays the contours or level curves of a function, where each contour line represents a constant value of the function.

2. How do I create a contour plot in Mathematica?

To create a contour plot in Mathematica, you can use the ContourPlot function. This function takes in the function you want to plot, the range of values for the x and y variables, and any other plot options you want to specify. For example, ContourPlot[f[x,y],{x,xmin,xmax},{y,ymin,ymax},PlotRange->All] will create a contour plot for the function f over the specified range.

3. What are some common problems in reporting contour plots in Mathematica?

Some common problems in reporting contour plots in Mathematica include not specifying a proper range of values for the variables, not using appropriate plot options, and not clearly labeling the plot. Additionally, issues may arise if the function being plotted is not properly defined or if there are errors in the data being used.

4. How can I customize my contour plot in Mathematica?

You can customize your contour plot in Mathematica by using various plot options such as PlotRange, ColorFunction, and ContourLabels. You can also add labels, titles, and legends to your plot using the PlotLabel, AxesLabel, and PlotLegends functions. Additionally, you can change the appearance of the plot by adjusting the colors, line styles, and thickness of the contour lines.

5. Can I export my contour plot from Mathematica to other software or formats?

Yes, you can export your contour plot from Mathematica to other software or formats such as PNG, PDF, or SVG. You can do this by using the Export function and specifying the desired file type. Keep in mind that the quality and resolution of the exported plot will depend on the size and resolution of your original plot in Mathematica.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
903
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
575
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
228
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Back
Top