Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I tried to convince Mathematica 8 to plot a density map of a function:

$$f(x,y) = \frac{2(x^2 - y^2)-1}{(x^2 + y^2)^2}$$

with color scheme called "TemperatureMap". At $x = \pm 1$, $y = 0$ it's completely correct, but at $y = \pm 1$, $x = 0$, it shows white color, where, in fact, it should be blue. I'm only interested in the region $x^2 + y^2 > 1$, so I added the command: ColorFunctionScaling -> False and manually rescaled my function to take values only between 0 and 1:

$$g(x,y) = \frac14 (3+f(x,y))$$

as I know where the maxima and minima occur in the region I'm interested in. The plot is even more strange, leaving almost no blue and, of course, at $x = 0, y = \pm 1$ it's white.

Whole input I used was (PlotPoints so I can get higher quality plot, Exclusions so I can see where's the boundary of region I'm interested in):

DensityPlot[(3 + 2*(x^2 - y^2)/(x^2 + y^2)^2 - 1/(x^2 + y^2)^2)/
  4, {x, -3, 3}, {y, -3, 3}, PlotPoints -> 100, 
 ColorFunction -> "TemperatureMap", Exclusions -> {x^2 + y^2 == 1}, 
 ColorFunctionScaling -> True]

Mathematica graphics

I expected a similar density map to the second image on this page. Instead the space approximately $(y/1.2)^2 + x^2 < 1$ is white. The region left of the white part is not exactly an ellipse, it looks like a ladyfinger. Where did I make a mistake?

I tried to plot a constant function 0 and 1 while ColorFunctionScaling being false and it correctly showed whole plot blue and red respectively. I don't have the slightest clue what went wrong.

I'd appreciate any help.

share|improve this question
2  
The white region has very high values so it's clipped. You can adjust the clipping with PlotRange. PlotRange -> All clips nothing, but it's not useful here. PlotRange -> m {-1,1} clips below -m and above m. –  Szabolcs Jul 12 at 15:42
    
Wow, man, thanks, that's EXACTLY what needed to be done. Now it works like a charm. I still don't know how come it drawn the wrong for $g(x,y) = 1$ (I tried to produce contourplot with the similar effect), but now with this plotrange thing it works. –  user16320 Jul 12 at 15:51

1 Answer 1

up vote 1 down vote accepted

You need to tell Mathematica how you want clipping handled.

f[x_, y_] = 2*(x^2 - y^2)/(x^2 + y^2)^2 -
    1/(x^2 + y^2)^2 // Simplify;

Plot3D[f[x, y], {x, -3, 3}, {y, -3, 3},
 PlotRange -> {-1, 1},
 ClippingStyle -> None]

enter image description here

DensityPlot[f[x, y],
 {x, -3, 3}, {y, -3, 3},
 PlotPoints -> 100,
 ColorFunction -> "TemperatureMap",
 ClippingStyle -> Darker[Blue]]

enter image description here

From the example to which you linked, you presumably want a Disk rather than a circle for the region x^2 + y^2 < 1

DensityPlot[f[x, y],
 {x, -3, 3}, {y, -3, 3},
 PlotPoints -> 100,
 ColorFunction -> "TemperatureMap", 
 ClippingStyle -> Darker[Blue],
 Epilog -> {Gray, Disk[]}]

enter image description here

share|improve this answer
    
Bob Hanlon: thanks, that helped a lot, it's exactly what I wanted to achieve. Is there a similar way to specify how long vector should be in vectorplot? Due to few bad vectors near the origin which are too long because of singularity at origin no other vectors show. On the one hand I like to elminate those vectors at the origin, on the other hand I want it to keep the scale for other ones. –  user16320 Jul 12 at 16:14
    
@user16320 - If you have a question about VectorPlot ask another question with an appropriate subject line. Provide initial code that demonstrates issue. –  Bob Hanlon Jul 12 at 16:36

Your Answer

 
discard

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.