Message Boards Message Boards

0
|
2982 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Changing background color in the Scatter and Residual Plots

Hi,

How do I have a white background like the below figures: enter image description here

OBS = {0.32`, 0.38`, 0.44`, 0.5`, 0.56`, 0.62`, 0.68`, 0.74`, 0.8`, 
   0.86`, 0.92`, 0.98`, 1.04`, 1.1`, 1.16`, 1.22`, 1.28`, 1.34`, 1.4`,
    1.46`, 1.52`, 1.58`, 1.64`, 1.7`, 1.76`, 1.82`, 1.88`, 1.94`, 2.`,
    2.3`, 2.6`, 2.9`, 3.2`, 3.5`, 3.8`, 4.1`, 4.5`, 4.8`, 5.1`, 5.4`, 
   5.7`, 6.`, 6.3`, 6.6`, 6.9`, 7.2`, 7.5`, 7.8`, 8.1`, 8.4`, 8.7`, 
   9.`, 9.3`, 9.6`, 9.9`};

DL = {0.483434196`, 0.542136072`, 0.611382606`, 0.664992403`, 
   0.717187037`, 0.785657138`, 0.817604024`, 0.885892689`, 
   0.931595386`, 1.003924369`, 1.080474604`, 1.582081792`, 
   1.479712701`, 1.205274226`, 1.227835857`, 1.21714276`, 
   1.354210476`, 1.29943604`, 1.41451306`, 1.504191906`, 1.554809371`,
    1.546290679`, 1.688226935`, 1.734784029`, 1.797105286`, 
   1.818454316`, 1.819943037`, 1.948748007`, 2.210486301`, 
   2.219253757`, 2.633416779`, 3.377471292`, 3.177418498`, 
   3.419391237`, 3.667034246`, 5.109073793`, 5.757665578`, 
   3.838614605`, 5.040199976`, 4.043855305`, 6.759191326`, 
   7.710793921`, 5.528524842`, 6.68354987`, 6.052318273`, 6.33655636`,
    6.5210536`, 8.551142833`, 7.156680471`, 8.029122314`, 
   9.193555892`, 8.358085894`, 10.13449034`, 8.282363095`, 
   9.88117456`};

diff = MapIndexed[{First[#2], #1} &, DL - OBS];
pairs = Transpose[{DL, OBS}]
residual = 
  SmoothDensityHistogram[diff, ColorFunction -> "BlueGreenYellow", 
   PlotRange -> {{0, 60}, {-2, 2}}, Epilog -> Point[diff], 
   ImageSize -> 400, PlotLegends -> Placed[Automatic, Below], 
   FrameLabel -> {None, Style["Residuals", 14, Bold, Black]}];
scatter = 
  SmoothDensityHistogram[pairs, ColorFunction -> "Rainbow", 
   PlotRange -> {{0, 12}, {0, 12}}, 
   Epilog -> {Point[pairs], Line[{{0, 0}, {25, 25}}]}, 
   ImageSize -> 400];
Row[{residual, scatter}];

Thank you very much for your help :)

POSTED BY: M.A. Ghorbani
2 Replies
Posted 5 years ago

Use the colorBlender function from this great post to define a custom gradient that is white for low values and gradually progresses to darker values e.g.

enter image description here

The "Copy to clipboard" button will copy a pure function definition to the clipboard. Paste and set a symbol to its value.

colorFunction = 
 Blend[{{0.0491, 
     Directive[RGBColor[1., 0.9999694819562066, 0.9999847409781033], 
      Opacity[1]]}, {0.1298, 
     Directive[RGBColor[
      0.5867093919279774, 0.47226672770275424`, 0.7917906462195773], 
      Opacity[1]]}, {0.1767, 
     Directive[RGBColor[0.250728, 0.225386, 0.769152], 
      Opacity[1]]}, {0.2043, 
     Directive[RGBColor[0.24408, 0.361242, 0.816084], 
      Opacity[1]]}, {0.25, 
     Directive[RGBColor[0.266122, 0.486664, 0.802529], 
      Opacity[1]]}, {0.3125, 
     Directive[RGBColor[0.305919, 0.585575, 0.739666], 
      Opacity[1]]}, {0.375, 
     Directive[RGBColor[0.36048, 0.655759, 0.645692], 
      Opacity[1]]}, {0.4375, 
     Directive[RGBColor[0.429842, 0.701849, 0.540321], 
      Opacity[1]]}, {0.5, 
     Directive[RGBColor[0.513417, 0.72992, 0.440682], 
      Opacity[1]]}, {0.5625, 
     Directive[RGBColor[0.607651, 0.743718, 0.358588], 
      Opacity[1]]}, {0.625, 
     Directive[RGBColor[0.705038, 0.742591, 0.299167], 
      Opacity[1]]}, {0.6875, 
     Directive[RGBColor[0.794549, 0.721158, 0.260829], 
      Opacity[1]]}, {0.75, 
     Directive[RGBColor[0.863512, 0.670771, 0.236564], 
      Opacity[1]]}, {0.8125, 
     Directive[RGBColor[0.901014, 0.582826, 0.216542], 
      Opacity[1]]}, {0.875, 
     Directive[RGBColor[0.902853, 0.453964, 0.192014], 
      Opacity[1]]}, {0.9375, 
     Directive[RGBColor[0.878107, 0.293208, 0.160481], 
      Opacity[1]]}, {1., 
     Directive[RGBColor[0.857359, 0.131106, 0.132128], 
      Opacity[1]]}}, #] &

Use it in the plot

SmoothDensityHistogram[pairs, ColorFunction -> colorFunction, 
 PlotRange -> {{0, 12}, {0, 12}}, 
 Epilog -> {Point[pairs], Line[{{0, 0}, {25, 25}}]}, 
 MaxRecursion -> 3, ImageSize -> 400]

enter image description here

POSTED BY: Rohit Namjoshi

Dear Rohit,

Thank so much for your help. It was very very useful for my purpose.

Regards

POSTED BY: M.A. Ghorbani
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract