2
$\begingroup$

I would like to produce a plot where the background color is not uniform (e.g. all white) but rather changing as function of the slope of the line that is plotted. A concrete example is:

data={{1., 315.457}, {0.997146, 230.976}, {0.988606, 128.556}, {0.974444,74.4523},
      {0.954769, 47.2897}, {0.929731, 32.5402},{0.899519,23.8385}, {0.864364, 18.3407},
      {0.824533, 14.6737}, {0.78033,12.1217}, {0.732091,10.2853}, {0.680182, 8.92909},
      {0.625,7.90752}, {0.566964, 7.12705}, {0.506515, 6.52556}, {0.444114,6.06067},
      {0.380236, 5.70282}, {0.315367, 5.43103}, {0.25,5.23019}, {0.184633, 5.08936}}

where I need a white background on the left ($x<0.6$), that fades to red when going to the right ($x=1$). I am struggling on how to achieve it by programming.

$\endgroup$
2
  • $\begingroup$ Like this? $\endgroup$
    – J. M.'s torpor
    Mar 6 '18 at 14:36
  • $\begingroup$ yes! It would be ideal if one could also change the 'slope' of the color gradient. $\endgroup$
    – Luigi
    Mar 6 '18 at 14:37
3
$\begingroup$

You could use DensityPlot[] to generate the background, and Lighter[] + LogisticSigmoid[] for coloring:

DensityPlot[x, {x, 0, 1}, {y, 5, 316}, AspectRatio -> 1/GoldenRatio,
            ColorFunction -> (Lighter[Red, 1 - LogisticSigmoid[100 (# - 0.65)]] &), 
            Epilog -> {Directive[AbsolutePointSize[6], ColorData[97, 1]], Point[data]}]

fading background

You can tweak the 100 and 0.65 in LogisticSigmoid[100 (# - 0.65)] to adjust the fading.

$\endgroup$
2
  • $\begingroup$ can I do this also with ListPlot? $\endgroup$
    – Luigi
    Mar 6 '18 at 15:00
  • 1
    $\begingroup$ Yes; remove the part with Epilog, and do Show[DensityPlot[(* stuff *)], ListPlot[(* stuff *)]]. $\endgroup$
    – J. M.'s torpor
    Mar 6 '18 at 21:13

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.