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

This is an example from Mathematic Help,

DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},  
  ColorFunction -> "SunsetColors", PlotLegends -> Automatic]

We can notice that the density values are from -1.0 to 1.0. However, I want to change this automatic density range to other values, for example, 0 to 0.5. Of course, the density plot should be different.

This should be simple, however, I have no idea about it. Can you tell me how to change it? Thanks!

share|improve this question
up vote 6 down vote accepted

PlotRange accepts up to three ranges of values for plots that have a third dimension. So, you would do this

DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},  
  ColorFunction -> "SunsetColors", PlotLegends -> Automatic,
  PlotRange -> {Automatic, Automatic, {0, 0.5}}

where the first two instances of Automatic are for the x and y coordinates.

share|improve this answer
Thanks! I just need this command---PlotRange. – Orders Feb 26 '13 at 13:39
@Orders don't forget to mark the best answer as accepted. I normally wait a day before doing so, though, just in case superior answers come in. – rcollyer Feb 26 '13 at 14:16

You could try Rescale:

 Rescale[Sin[x] Sin[y], {-1, 1}, {0.25, 0.5}],
 {x, -4, 4}, {y, -3, 3},
 ColorFunction -> "SunsetColors",
 PlotLegends -> Automatic]


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.