Tag Info

Hot answers tagged

30

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, ...


24

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[ ...


24

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 ...


22

There is indeed an alternative which you might should consider. You almost got it yourself by the given analysis of the situation in your question. While Plot3D does only care of a good resolution of the function you plot and not the function you use for coloring, DensityPlot uses your color function from the beginning and tries to resolve this as best as ...


21

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[{#}]] & /@ ...


20

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, ...


19

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] := . . . ...


18

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[{#}]] ...


17

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 ...


17

Similar to halirutans answer you can let DensityPlot determine the "good points", and then ListPlot3D those: ptsdp = Reap[ DensityPlot[Arg[f[a + I b]], {a, -5, 5}, {b, -5, 5}, PlotPoints -> 25, ColorFunction -> "DarkRainbow", EvaluationMonitor :> Sow[{a, b}]]][[-1, 1]]; ListPlot3D[({#[[1]], #[[2]], Abs@f[Complex @@ #]}) & /@ ...


17

It looks like the blend colours can be extracted with: DataPaclets`ColorDataDump`getColorSchemeData["SunsetColors"][[5]] (* {RGBColor[0., 0., 0.], RGBColor[0.372793, 0.1358, 0.506503], RGBColor[0.788287, 0.259816, 0.270778], RGBColor[0.979377, 0.451467, 0.0511329], RGBColor[1., 0.682688, 0.129771], RGBColor[1., 0.882236, 0.491094], RGBColor[1., 1., ...


17

Regarding your 1. question A density plot is clearly not recommended for your problem. Firstly, a density is AFAIK per definition not complex, but let's ignore this for a moment. The real neck-breaker here is, that ListDensisityPlot interpolates the values if you don't turn it explicitly off. And even if you turn it off, a ListDensityPlot will create a ...


16

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 ...


16

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_, ...


16

This may be what you are looking for. img = Import["http://i.imgur.com/Wd9lPRa.jpg"] Now use DominantColors. Graphics[{#, Disk[]}] & /@ DominantColors[img, 4]


16

How does Colorize work Colorize does use DarkRainbow as a default color scheme. What Colorize does first is setting up a hashtable with RGB values from DarkRainbow through DataPaclets`ColorDataDump` The next operation is setting up a list of indices from the original image, iterating through the internal hash-table to fill a list of color triplets and ...


15

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 ...


15

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 ...


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, ...


15

First, there is no need to use Module in your sample code above. You could write simply: CCGray[pic_?ImageQ] := ColorConvert[pic,"GrayScale"] Now, if you want to manage the channel mixing manually you can use ImageApply and Dot: customGray[img_?ImageQ, ker_?VectorQ] := ImageApply[ker.# &, img] img = Import["http://i.stack.imgur.com/wtlqF.jpg"]; ...


14

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 ...


14

(too long for a comment) Plot[{ColorData["VisibleSpectrum"][x][[1]], ColorData["VisibleSpectrum"][x][[2]], ColorData["VisibleSpectrum"][x][[3]]}, {x, 380, 750}, PlotStyle -> {Red, Green, Blue}] It doesn't seem that you'll be able to obtain Yellow (RGBColor[1, 1, 0]) from ColorData["VisibleSpectrum"]; unfortunately, the docs say nothing ...


14

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 ...


14

You need to add ColorFunctionScaling -> False as an option to SphericalPlot3D. That should do the trick color[Θ_, Φ_] := RGBColor[(Sign[Re[SphericalHarmonicY[2, 1, Θ, Φ]]] + 1)/ 2, 0, (-Sign[Re[SphericalHarmonicY[2, 1, Θ, Φ]]] + 1)/ 2]; SphericalPlot3D[ Re[SphericalHarmonicY[2, 1, Θ, Φ]], {Θ, 0, π}, {Φ, 0, 2 π}, ColorFunction -> ...


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

For those without v9, here's another attempt based on FindClusters, but using a different colour space. The idea is to reduce the effect of overall brightness on the "distance" between colours, so that the clustering gives more weight to differences of hue and is less likely to pick out different shades of gray. newspace[{r_, g_, b_}] := {r - g, b - g, (r + ...


14

Another problem is that the Table[..., {x, -L1, L1, δ}, {y, -L2, L2, δ}] produces unpacked array. f = With[{fun = Evaluate[ Sum[Exp[ω I Sqrt[(#1 - 1.0 Cos[θ])^2 + (#2 - 1.0 Sin[θ])^2]], {θ, 2 Pi/n, 2 Pi, 2 Pi/n}]] &}, Compile[{{x, _Real}, {y, _Real}}, {Mod[Arg[#]/(2.0 Pi), 1], 1.0, Abs[#/2]} &@fun[x, y], ...


14

The default colours for charts are defined by Charting`CommonDump`rogerStyles. For up to five different colours the values are hard-coded: Charting`CommonDump`rogerStyles[5] (* {RGBColor[0.798413, 0.82472, 0.968322], RGBColor[0.733333, 1., 0.833722], RGBColor[1, 0.986999, 0.742123], RGBColor[1, 0.860624, 0.662562], RGBColor[1, 0.696086, 0.721935]} *) ...


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]


13

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] (* ...



Only top voted, non community-wiki answers of a minimum length are eligible