1
$\begingroup$

I have a problem in the color scheme in a 2D spectra.

After a lot of calculations, i can generate a picture like this

Generated spectra

in the last part using this instructions

ListContourPlot[dat, ContourShading -> None, 
InterpolationOrder -> 3, 
Contours -> Delete[CNTRFT[dat], Length[CNTRFT[dat]]/2 + 1/2], 
ContourStyle -> CLRFT[dat], PlotRange -> {Ran[[1]], Ran[[2]], All}, 
DataRange -> Ran, ColorFunctionScaling -> False, Axes -> False]

ListDensityPlot[dat, PlotRange -> {Ran[[1]], Ran[[2]], All}, 
ColorFunction -> (Hue[.45 - #] &), ColorFunctionScaling -> False, 
DataRange -> Ran, InterpolationOrder -> 3, Axes -> False]

the color in the corners (aquamarine) are for zero value, blue and violet are for negative values and yellow and green for positive values. Now i need to clean this color, because i want to train a convolutional network to identify spectra. Then I need the spectra with a color scheme with white for the zero value. I try to use diferent forms as, for example change the Hue value as

(Hue[.45 - #, 0 - #, 1] &) 

or

(Hue[.45 - #, 0 + #, 1] &) 

but, i only obtain the negative or positive values and zero.

negative values positive values

I have this problem for a time and i need to continue. any suggestions?

Thanks a lot for the help.

Regards.

$\endgroup$
  • $\begingroup$ My interpretation of your question is that you want the function to plot as white anywhere that it is zero (or perhaps just very close to zero). Is that correct? If so, you could try something like ColorFunction -> (If[# < 0.001, White, Hue[0.45 - #]]&). If you want to only replace it when it's exactly equal to zero, then you could use # == 0 instead. $\endgroup$ – MassDefect Jun 2 at 6:16
  • $\begingroup$ Is something like these, but I need a continuous color change. A color scheme were the white corresponds to the zero value $\endgroup$ – Santiago Marín Agudelo Jun 2 at 6:20
2
$\begingroup$

You can create color schemes with white in the middle using Blend:

sample[blendColors_] := Table[
  Blend[
   blendColors,
   Rescale[x, {-1, 1}]
   ], {x, {-1, -0.5, 0, 0.5, 1}}
  ]

sample[{Red, White, Blue}]

Mathematica graphics

sample[{Purple, Blue, Cyan, White, Green, Yellow, Orange}]

Mathematica graphics

Another example where I don't rely on the number of colors on either side of White:

sample[{{0.1, Purple}, {0.2, Blue}, {0.5, White}, {1, Red}}]

Mathematica graphics

And finally one with values that are negative and haven't been rescaled before being passed to Blend:

Table[
 Blend[
  {{-1, Purple}, {-0.5, Blue}, {0, White}, {1, Red}},
  x
  ], {x, {-1, -0.5, 0, 0.5, 1}}
 ]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Hi, this is an excellent approach, but there is a problem, in the second picture the colors reverse. But with this example I found a solution to my problem. Thanks a lot. $\endgroup$ – Santiago Marín Agudelo Jun 4 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.