[Mathematica]Frustratedhow to color a plot according to the values?

  • Mathematica
  • Thread starter hanson
  • Start date
  • Tags
    Color Plot
In summary, the conversation discussed the frustration of searching for a way to plot a contourplot with colored values. The desired outcome was for negative values to be blue and positive values to be red, with a gradient in between. A suggestion was made to use the contour option and the help contextColorFunction resource. Another user shared a syntax for the ColorFunction and a user-written Mathematica notebook was also mentioned as a helpful resource.
  • #1
hanson
319
0
Hi all.
I have been searching over the web for some time, kind of frustrated...
I would like to plot the contourplot of a function, and I would like the contourplot to be colored.
The rule is that...the negative values should be blue in colors and the positive values should be red in colors, but I also want some gradient between these two limits...
I suppose this can be quite easily done, but I still don't know how to do that...
Anyone knows? Please help. Thanks.
 
Physics news on Phys.org
  • #2
Try playing with the contour option:
contour-># of contour lines
and contourstyle

they should be in the help context
 
  • #3
ColorFunction

http://documents.wolfram.com/mathematica/functions/ColorFunction

I can't remember the syntax (haven't had a Mathematica license in years), but you want something like ColorFunction -> (RGBColor[1.0#, 0.0, (1.0-1.0#)]&) or similar - you can fiddle with the constants to change the parametric variation, even make it nonlinear if you want.
 
Last edited by a moderator:
  • #4
Thanks for the replies!
I have found a user-written Mathematica notebook which do exactly what i want. Thanks.
 

1. How can I color a plot in Mathematica based on the values?

In Mathematica, you can use the ColorFunction option to set a color scheme for your plot based on the values. For example, if your plot represents a function f(x,y), you can use the option ColorFunction -> ColorData["Rainbow"][f(x,y)]. This will color the plot using the colors from the Rainbow color scheme based on the values of the function.

2. Can I specify my own color scheme for a plot in Mathematica?

Yes, you can specify your own color scheme by defining a custom color function and using it in the ColorFunction option. For example, you can create a function called myColorFunction that takes in a value and returns a specific color, and then use it as ColorFunction -> myColorFunction[value] in your plot.

3. How can I add a color legend to my plot in Mathematica?

To add a color legend to your plot, you can use the option ColorFunctionScaling -> False to make sure the colors are mapped directly to the values. Then, you can use the option PlotLegends -> BarLegend[{ColorData["Rainbow"], {min, max}}] to add a color bar legend to your plot, where min and max are the minimum and maximum values of your plot.

4. Is it possible to change the color of individual data points in a plot?

Yes, you can use the option PlotStyle -> {color1, color2, ...} to specify a different color for each data point in your plot. The colors will be applied in the order of the data points, so the first color will be applied to the first data point, the second color to the second data point, and so on.

5. Can I use a different color scheme for different parts of my plot in Mathematica?

Yes, you can use the option ColorFunction -> {colorFunction1, colorFunction2, ...} to specify different color functions for different parts of your plot. For example, you can use the option ColorFunction -> {ColorData["Rainbow"], ColorData["TemperatureMap"]} to use the Rainbow color scheme for one part of the plot and the TemperatureMap color scheme for another part.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top