Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some quantity varying with time (horizontal axis of the plot): it first oscillates then it has a jump (larger than the amplitude of the oscillations), then it continues oscillating. I have that quantity for a discrete set of cases (vertical axis of the plot).

I would like to find an option for ListDensityPlot that would allow me to really emphasize that jump: I don't want a nice smooth color scheme but rather one that would make the small oscillations invisible and would focus on the larger jump.

I can I control ListDensityPlot to do that ?

share|improve this question
(List)DensityPlot is for a two-variable function such as $f(x,y)$, but from your description I understood that you have a single quantity varying in a single variable (time), i.e. $f(t)$. Can you clarify? I thought you had something like Plot[Table[Sin[x] + 3 UnitStep[x - 20] + i, {i, 0, 10, 2}] // Evaluate, {x, 0, 40}]. – Szabolcs Jul 24 '12 at 10:19
It would be best if you could give an example, or maybe sample data (with as much information about the location of the jump as possible). – Szabolcs Jul 24 '12 at 10:21
up vote 6 down vote accepted

Sample data

pw = Piecewise[{{Sin[5 x + y], x < 5}, {3 + Sin[5 x + y], x > 5}}];

tab = Table[pw, {y, 0, 10, 0.1}, {x, 0, 10, 0.1}];

Expansion function

expand[c_ /; c == 0] = # &;
expand[c_] := 1/2 - ArcTan[c - 2 c #] / ArcTan[c] / 2 &

expand[x] generates a function with expansion factor x.

  Plot[expand[c][x], {x, 0, 1}],
  {c, 0, 10, 2}
] ~Partition~ 3 // Grid

Mathematica graphics

With expansion

We can use this on the data passed to the ColorFunction like this:

ListDensityPlot[tab, ColorFunction -> (ColorData["SunsetColors"] @ expand[10][#] &)]

Mathematica graphics

Without expansion

The same plot without expansion:

ListDensityPlot[tab, ColorFunction -> ColorData["SunsetColors"]]

Mathematica graphics

share|improve this answer


data = Table[
   With[{r = RandomReal[{0, 5}], 
     t = RandomReal[{0, 2 Pi}]}, {r Cos[t], r Sin[t], 
     Sin[r^2]/r^2}], {10^4}];

ListDensityPlot[data, Mesh \[Rule] None, InterpolationOrder -> 0]

Mathematica graphics


ListDensityPlot[data, Mesh -> None, InterpolationOrder -> Automatic]

Mathematica graphics

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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