I have the following code.

\begin{axis}[domain = -2:2
         ,y domain = -2:2,view={0}{90}] 

\addplot3[contour gnuplot={number=10},thick,domain=-2:2]

But I'd like it to plot just the area inside a circle x^2+y^2 < 1 Any Idea?

  • Why not a simple circle filled? – percusse Feb 10 '13 at 2:19
  • @percuße I want it to be filled by the mentioned contour. How? – batista cori Feb 10 '13 at 2:21
  • Do you mean clipping with a circle or a circle under these countours? – percusse Feb 10 '13 at 2:23
  • @percuße clipping with a circle. – batista cori Feb 10 '13 at 2:24

I can't see where that extra 3.5 scaling factor comes from but this should be robust to scaling and other shifts etc.

Edit : the clipping path can be much simplified thanks to Christian's correction.

\begin{axis}[domain = -2:2,y domain = -2:2,view={0}{90},grid=both] 
\clip (axis cs:0,0) circle (1 and 1); 
\addplot3[contour gnuplot={number=10},thick,domain=-2:2]{0.5*exp(-0.2*abs(x)-0.2*abs(y))}; 

enter image description here

|improve this answer|||||
  • If you omit units after the circle path, the radii will be interpreted as (pgfplots!) axis units: \clip ... circle (1 and 1); . Note furthermore that \pgfplotsextra is the correct choice, but is is inserted automatically if you omit it. – Christian Feuersänger Feb 10 '13 at 16:15
  • @ChristianFeuersänger Much better and obvious. I didn't know that. Thank you. By the way can you see why the need to scale with 3.5? – percusse Feb 10 '13 at 16:19
  • This is a consequence of the internal data scalings. Consequently, the 3.5 would have been wrong if the limits where from, say, -200 .. 200. – Christian Feuersänger Feb 10 '13 at 21:07

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.