(Created page with "= ''Mathematica'' colours = Mathematica has a rather extensive support for colors, but more often than not, it needs tinkering with. We like to use the ''SunsetColors'' ...")
 
m (Mathematica colours)
 
(4 intermediate revisions by one user not shown)
Line 2: Line 2:
  
 
[[Mathematica]] has a rather extensive support for colors, but more often than not, it needs tinkering with.
 
[[Mathematica]] has a rather extensive support for colors, but more often than not, it needs tinkering with.
 +
 +
Colors can be retrieved from hexadecimal codes with a # in a string:
 +
 +
<wz tagtotip="rgbcode">[[File:Screenshot_20240921_115107.png|120px]]</wz>
 +
<span id="rgbcode">RGBColor["#0e64fc"]</span>
  
 
We like to use the ''SunsetColors'' color scheme:
 
We like to use the ''SunsetColors'' color scheme:
Line 8: Line 13:
  
 
<center>[[Image:mathematica-SunsetColors.png|300px]]</center>
 
<center>[[Image:mathematica-SunsetColors.png|300px]]</center>
 +
 +
A more serious and clear scheme is to blend between red and blue with white as an intermediate. We use this for convention for bunching/antibunching (white is uncorrelated):
 +
 +
<pre>
 +
ColorFunction -> (Blend[{White, Blue, Red}, #] &)
 +
</pre>
  
 
This module exports a list of ''n'' colors distributed along the gradient:
 
This module exports a list of ''n'' colors distributed along the gradient:
Line 15: Line 26:
 
  Module[{}, Table[ColorData["SunsetColors"][i], {i, 0, 1, 1/(n - 1)}]]
 
  Module[{}, Table[ColorData["SunsetColors"][i], {i, 0, 1, 1/(n - 1)}]]
 
</pre>
 
</pre>
 +
 +
A blending of colors can be done with <tt>blend</tt>, e.g., that generates a smooth transition from red to blue in <tt>n</tt> steps:
 +
 +
<pre>
 +
Table[{Blend[{Red, Blue}, x]}, {x, 0, 1, 1/(n+1)}]
 +
</pre>
 +
 +
In <tt>ListPlot</tt>, to have points (markers) have the same color as the lines (which should be the default), add:
 +
 +
<pre>
 +
PlotMarkers -> Graphics@{Point[{0, 0}]
 +
</pre>
 +
 +
The default colors in modern versions of Mathematica is taken from:&nbsp;[https://mathematica.stackexchange.com/questions/54629/what-are-the-standard-colors-for-plots-in-mathematica-10]
 +
 +
<pre>
 +
ColorData[97, "ColorList"]
 +
</pre>
 +
 +
One can find the other useful themes&nbsp;[https://mathematica.stackexchange.com/questions/54486/how-to-access-new-colour-schemes-in-version-10]
 +
 +
<pre>
 +
"Color"/. Charting`$PlotThemes
 +
(* BackgroundColor, BlackBackground, BoldColor, ClassicColor, CoolColor,
 +
    DarkColor,GrayColor, NeonColor,PastelColor, RoyalColor, VibrantColor, WarmColor,
 +
    DefaultColor, EarthColor, GarnetColor, OpalColor, SapphireColor, SteelColor,
 +
    SunriseColor, TextbookColor, WaterColor} *)
 +
 +
Grid[{#,Row@(("DefaultPlotStyle"/.(Method/.
 +
  Charting`ResolvePlotTheme[#,  ListPlot]))/.
 +
      Directive[x_,__]:>x)}&/@("Color"/. Charting`$PlotThemes),Dividers->All]
 +
</pre>
 +
 +
<center><wz tip="Possible color themes from Mathematica. The default one in later versions is somewhere in the middle:">[[File:mathematica-default-colors.jpg|250px]]</wz></center>

Latest revision as of 09:53, 21 September 2024

Mathematica colours

Mathematica has a rather extensive support for colors, but more often than not, it needs tinkering with.

Colors can be retrieved from hexadecimal codes with a # in a string:

Screenshot 20240921 115107.png RGBColor["#0e64fc"]

We like to use the SunsetColors color scheme:

ColorData["SunsetColors"]
Mathematica-SunsetColors.png

A more serious and clear scheme is to blend between red and blue with white as an intermediate. We use this for convention for bunching/antibunching (white is uncorrelated):

ColorFunction -> (Blend[{White, Blue, Red}, #] &)

This module exports a list of n colors distributed along the gradient:

lcol[n_] := 
 Module[{}, Table[ColorData["SunsetColors"][i], {i, 0, 1, 1/(n - 1)}]]

A blending of colors can be done with blend, e.g., that generates a smooth transition from red to blue in n steps:

Table[{Blend[{Red, Blue}, x]}, {x, 0, 1, 1/(n+1)}]

In ListPlot, to have points (markers) have the same color as the lines (which should be the default), add:

PlotMarkers -> Graphics@{Point[{0, 0}]

The default colors in modern versions of Mathematica is taken from: [1]

ColorData[97, "ColorList"]

One can find the other useful themes [2]

"Color"/. Charting`$PlotThemes
 (* BackgroundColor, BlackBackground, BoldColor, ClassicColor, CoolColor,
    DarkColor,GrayColor, NeonColor,PastelColor, RoyalColor, VibrantColor, WarmColor, 
    DefaultColor, EarthColor, GarnetColor, OpalColor, SapphireColor, SteelColor,
    SunriseColor, TextbookColor, WaterColor} *)

 Grid[{#,Row@(("DefaultPlotStyle"/.(Method/. 
   Charting`ResolvePlotTheme[#,   ListPlot]))/.
      Directive[x_,__]:>x)}&/@("Color"/. Charting`$PlotThemes),Dividers->All]
Mathematica-default-colors.jpg