Hot answers tagged color
28
CurrentValue["Color"] seems to be doing the trick (not documented).
mydisk[p_, r_] := {Dynamic[EdgeForm[Darker[CurrentValue["Color"]]]],
Disk[p, r]}
Dynamic is needed because the value has to be evaluated by FrontEnd at the time of rendering. Here is the result:
Graphics[{EdgeForm[AbsoluteThickness[10]], Red, mydisk[{0, 0}, 1],
Green, mydisk[{1, ...
22
Instead of individually controlling the RGB colors, which is much harder, use the output of your function (a scalar) as the input to some color function.
Here's an example:
SphericalPlot3D[1, {θ, 0, π}, {Φ, 0, 2 π},
ColorFunction -> Function[{x, y, z, θ, Φ, r},
ColorData["DarkRainbow"][Cos[5 θ] + Cos[4 Φ]/2]],
ColorFunctionScaling ...
21
One way would be to use ColorConvert to convert the RGB or Hue values to gray scale. Here's an example:
Plot[{Sin[x], Cos[x], Exp[-x^2], Sinc[π x]}, {x, 0, π}] /.
x : _RGBColor | _Hue | _CMYKColor :> ColorConvert[x, "Grayscale"]
For 2D plots that accept a ColorFunction, you can simply use GrayLevel to get the plot in grayscale as:
DensityPlot[
...
19
Using IntegerDigits to convert directly to base 256:
hexToRGB = RGBColor @@ (IntegerDigits[
ToExpression@StringReplace[#, "#" -> "16^^"], 256, 3]/255.) &
hexToRGB["#FF8000"]
(* RGBColor[1., 0.501961, 0.] *)
Edit
Shorter version, since somebody mentioned golfing...
hexToRGB = RGBColor @@ (IntegerDigits[# ~StringDrop~ 1 ~FromDigits~ 16, 256, ...
17
The following updated solution is based on the existing solutions from Janus and belisarius, but I consider it an improvement.
Corrected to work with Plot[..., {PlotStyle -> ...}] , and to move the assignment from Rule.
Supporting functions
ClearAll[toDirective, styleJoin]
toDirective[{ps__} | ps__] :=
Flatten[Directive @@ Flatten[{#}]] & /@ ...
16
An alternative to R.M's method that became available in version eight is the Texture[] directive, which allows one to wrap textures on surfaces. For this application, we can wrap the output of DensityPlot[] (after some postprocessing with Image[]) on a sphere. One benefit to this approach is that DensityPlot[] takes care of scaling the spherical harmonics ...
15
Here is one take on it -- the hard part was estimating how the PlotStyle option is turned into a list of directives. I think this works as the internal implementation:
canonicalPlotStyle::usage =
"Turn a PlotStyle option into the canonical form {_Directive...}";
canonicalPlotStyle[ps_] := Replace[ps, {
a_List :> (Flatten[Directive @@ Flatten[{#}]] ...
15
Seems that the automatic setting of MaxPlotPoints is too low. You can set it to something high (or even Infinity) to get around this.
m = 200;
list = Table[Table[RandomInteger[], {j, 1, 10}], {i, 1, m}];
Tally[Flatten[list]]
MatrixPlot[list, FrameTicks -> None, ImageSize -> {300, 300},
ColorRules -> {0 -> White, 1 -> Red}, MaxPlotPoints ...
15
colorQ = Quiet @ Check[Blend @ {#, Red}; True, False] &;
colorQ /@ {Red, Hue[0.5], GrayLevel[0.5], CMYKColor[0, 1, 1, 1/2], Opacity[0.5, Purple]}
{True, True, True, True, True}
colorQ /@ {17, 1.3, Pi, "not a color", {1, 2, 3}, Hue["bad arg"]}
{False, False, False, False, False, False}
You would use: drawShape[color_?colorQ] := . . .
...
15
Background takes only simple parameters.
You could try this:-
lp = ListPlot[Prime[Range[25]], Filling -> Axis,
(* Default PlotRangePadding *)
PlotRangePadding -> {Scaled[0.02], Scaled[0.02]}];
{{xmin, xmax}, {ymin, ymax}} = {#1, #2*1.02} & @@@
(PlotRange /. Options[lp, PlotRange]);
grad = Graphics[Polygon[
{{xmin, ymin}, {xmax, ...
14
Conversion Formula
ColorConvert uses the following formula for "Grayscale" conversion:
$ \mathrm{Grayscale} = 0.299 R + 0.587 G + 0.114 B$
where $R$, $G$, and $B$ are normalized.
Interactive Example
The following manipulate example will help you finding (and confirming) the conversion based on a fixed $\mathrm{Grayscale}$ and $R$ values.
f[g_, gs_, ...
14
Here is my attempt to figure out how the correct colorspace linearization should be made. I used specially designed test images by Eric Brasseur for comparison of two colorspace linearization algorithms. The first algorithm is just an implementation of the corresponding formulae from the Specification of sRGB made by Jari Paljakka who started the discussion ...
14
It's not just the order, the actual colours themselves can change depending on how many you ask for. Sometimes, these colours might not even be in your image! The reason is because DominantColors does a clustering operation and returns the mean of the n clusters in the LAB space and doesn't necessarily pick the colours that appear common to the eye ...
14
This may be what you are looking for.
img = Import["http://i.imgur.com/Wd9lPRa.jpg"]
Now use DominantColors.
Graphics[{#, Disk[]}] & /@ DominantColors[img, 4]
13
One way is to use Joined -> True and replace Line with Point afterwards:
ListPlot[RandomReal[1, {100, 2}], PlotStyle -> Thick, Joined -> True,
ColorFunction -> Function[{x, y}, Hue[(x + y)/2]]] /. Line[a__] :> Point[a]
12
I propose using Graphics primitives:
data = RandomReal[1, {1000, 2}];
Graphics[{Thick, Point[data, VertexColors -> (Hue /@ Mean /@ data)]},
AspectRatio -> 1/GoldenRatio,
Axes -> True
]
Here's another method that does not perform as well, but I like the style:
ListPlot[List /@ data, BaseStyle -> Thick, PlotStyle -> (Hue /@ Mean /@ ...
12
The problem is not that the test is only evaluated once but that by default ColorFunctionScaling is set to True which means that the coordinates are rescaled to lie in the interval $[0,1]$ before being fed to ColorFunction. Try this instead
Plot[x, {x, 0, 20}, Filling -> Axis,
ColorFunction -> Function[{x, y}, Piecewise[{{Green, y > 10}, {Blue, y ...
12
For any color c:
f[c_, x_?NumericQ] := ColorConvert[Blend[{White, c, Black}, x], "Grayscale"][[1]]
Find a similar hue (ie lighter or darker) color for gray tone .3
findBlend[myColor_, Grayness_] := FindRoot[f[myColor, x] == Grayness, {x, 1/2}];
blend = findBlend[Blue, .3]
Test it
col = Quiet[Blend[{White, c, Black}, x] /. c -> Blue /. blend]
(* ...
12
One simple way to go about it:
ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2 Pi}] /.
Line[l_List] :> {{Red, Polygon[l]}, {Black, Line[l]}}
If you want the border to be a tad more prominent:
ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2 Pi}] /.
Line[l_List] :> {{Red, Polygon[l]}, {Directive[AbsoluteThickness[3], Black], Line[l]}}
An alternative ...
12
I just had a look at the colours as they are produced on my screen. I have been working with lasers for many (30+) years and can assure you that a 591nm laser line is fairly yellow, around 635nm is fairly red and 488nm appears as cyan, which resembles the colours of the disks well. Are you sure you are not confusing the wavelength of the maximum of black ...
12
You need to add ColorFunctionScaling -> False as an option to SphericalPlot3D. That should do the trick
color[\[Theta]_, \[Phi]_] :=
RGBColor[(Sign[Re[SphericalHarmonicY[2, 1, \[Theta], \[Phi]]]] + 1)/
2, 0, (-Sign[Re[SphericalHarmonicY[2, 1, \[Theta], \[Phi]]]] + 1)/
2];
SphericalPlot3D[
Re[SphericalHarmonicY[2, 1, \[Theta], \[Phi]]], ...
12
Another potentially useful command of this kind is the CommonestFilter which looks locally about each pixel and chooses the most common value to display. Setting the neighborhood large causes large regions of constant color. For example
img = Import["http://i.imgur.com/Wd9lPRa.jpg"]
CommonestFilter[img, n]
where img is the image from the OPs question ...
11
This looks like a defect in the implementation. Here is a simple test:
traced =
Trace[
DensityHistogram[RandomVariate[BinormalDistribution[.5], 500],
ColorFunction -> (ColorData["Rainbow"][#] &)]
];
FreeQ[traced,Sow]
False
What this means is that Sow is also used in the implementation, and apparently without tags, so when Reap is ...
11
distance = {0.245, -0.235, 0.053, -0.048, -0.128, -0.007, -0.075, -0.067, -0.005, 0.082}
Show[Function[attributes,
Graphics[{Blend[{{-Max[Abs[distance]], Red}, {0, LightRed}, {0,
LightGreen}, {+Max[Abs[distance]], Green}},
distance[[attributes]]],
Rectangle[{If[distance[[attributes]] < 0,
distance[[attributes]]*10, 0],
...
11
You can Rescale your points that are passed to ColorFunction so that they're between 0.05 and 0.95 as in the example below:
data = Table[Sin[i + j^2], {i, 0, 3, 0.1}, {j, 0, 3, 0.1}];
ListContourPlot[data, ColorFunction -> (ColorData["Rainbow"][
Rescale[#, {0, 1}, {0.05, 0.95}]] &)]
11
A simple way is to use a ColorSetter.
Where color is the color you want to display, run
DynamicSetting@ColorSetter@color
You can also copy the result and use it as input in a notebook.
Illustration:
11
To my knowledge, as soon as you specify a ColorFunction, every point {x,y} no matter to which function it belongs is colorized by the same function.
If you want to achieve this behavior without modifying built-in functions, you could use the UpValues of an arbitrary symbol, for instance MultiColorFunction. With this, you specify how a plot-command has to ...
10
We can achieve such visual style with built-in tools, applying some color gradient along the rectangles. Using your data:
distance = {0.245, -0.235, 0.053, -0.048, -0.128,
-0.007, -0.075, -0.067,-0.005, 0.082}
BarChart will do the job:
BarChart[distance, ChartElementFunction -> ChartElementDataFunction[
"GradientScaleRectangle", ...
10
=== Update - all color gradients ===
You should check out some of the related Demonstrations. This is my version - a close reproduction of Wikipedia figures found on this page. Note, $l \geq |m|$ conditions is imposed. The code is below the image.
Manipulate[If[m > l, m = l];
Column[{
(* formula *)
TraditionalForm@SphericalHarmonicY[l, m, θ, ...
10
That's a good question. There does seem to be a considerable discrepancy versus the 1931 CIE diagram:
GraphicsGrid @ List @ Table[
Graphics @ {ColorData["VisibleSpectrum"][i], Disk[], White, Text[i]},
{i, 380, 700, 10}
]
Perhaps there was a miscalculation made in reducing the very large CIE color space values to sRGB triplets? sRGB, the ...
Only top voted, non community-wiki answers of a minimum length are eligible



