1
$\begingroup$

I would like to plot a figure using this kind of colorfunction in Mathematica. I opened the "Color Schemes" from the Palettes menu, but did not find a proper colorfunction.

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ Why not mention where you got this color gradient from? Also, have you seen this? $\endgroup$ Commented Jul 8, 2020 at 15:12

1 Answer 1

3
$\begingroup$

Here I've extracted a long thin part of your image to get the colours. Then I use the value provided by default ColorFunctionScaling from 0 (blue) to 1 (red), to extract the nearest colour or clip to the colours at the endpoints:

(* get the image and smooth it out to reduce the banding effects *)
img = GaussianFilter[Import["https://i.sstatic.net/fJlC6.png"],11];

(* Take a slice of the image from top to bottom, ignoring black and white parts, then reverse *)
colours = Reverse[ImageData[ImageTake[img, {105, -185}, {100, 120}]][[All, 1]]];

(* scaled from 0 (-50) to 1 (0) *)
scale = Length[colours];
(* select the part of the list near scaled up 'v' and clip to ends if necessary *)
mycf[v_] := RGBColor@colours[[Round[Clip[v*scale, {1, Length[colours]}]]]]

DensityPlot[-x y, {x, 0, 7}, {y, 0, 7}, ColorFunction -> mycf, PlotPoints -> 40]

colour function density plot

$\endgroup$
3
  • $\begingroup$ Hi, flinty, thank you for your solutions. Now I just updated this post. Could you have time to look at my new questions? $\endgroup$
    – Mr.2023
    Commented Jul 10, 2020 at 0:54
  • $\begingroup$ @C.E. ok.sorry I did not know this. I just post a new question. $\endgroup$
    – Mr.2023
    Commented Jul 10, 2020 at 6:25
  • $\begingroup$ @flinty Hi, flinty, can you help me for my new question? Thank you. mathematica.stackexchange.com/questions/225646/… $\endgroup$
    – Mr.2023
    Commented Jul 10, 2020 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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