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!


2 Answers 2


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.

  • $\begingroup$ Thanks! I just need this command---PlotRange. $\endgroup$
    – Orders
    Feb 26, 2013 at 13:39
  • $\begingroup$ @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. $\endgroup$
    – rcollyer
    Feb 26, 2013 at 14:16
  • $\begingroup$ Oddly enough, this isn't working for me. It's the first thing I've tried, but while the range of my data is about {500,1700}, setting PlotRange->{Automatic,Automatic,{0,4000}} doesn't change anything about the result. The solution here worked for me, though. $\endgroup$ Feb 4, 2018 at 23:44

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]



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.