2

I would like to plot the surface given by f(x,y) = 1/(1-xy) over the range [0,1]×[0,1], with the plot range being [0,5].

Update: I managed to obtain the above plot, but I want the red region to be smoothly connected. How can this be achieved without dramatically increasing the sampling frequency of the plot?

Perhaps there is a way to weight the sampling according to some arbitrary function?

My code:

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{tikzpicture}
\begin{axis}[domain=0:1,xmax=1,ymax=1,zmax=10,samples=50,
  unbounded coords=jump, filter point/.code={%
        \pgfmathparse
          {\pgfkeysvalueof{/data point/x} + \pgfkeysvalueof{/data point/y} > 1.8}%
            \ifpgfmathfloatcomparison
              \pgfkeyssetvalue{/data point/x}{nan}%
            \fi
          },
        ]
  \addplot3[surf] {1/(1-x*y)};
\end{axis}
\end{tikzpicture}
  • Use the smooth option. – manooooh Jun 24 '19 at 11:57
  • @manooooh I get a horrible thing. imgur.com/a/rJPzxBq – Jack Tiger Lam Jun 24 '19 at 12:06
  • Post your code here. Don't post an image elsewhere. – Teepeemm Jun 24 '19 at 12:11
  • @Teepeemm I have added my code to my post. – Jack Tiger Lam Jun 24 '19 at 12:12
2

The arguably simplest way to go is to clip the corners away.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:1,xmax=1,ymax=1,zmax=10,samples=50]
  \clip (0,0,0) -- (1,0,0)  -- (1,0.8,0) -- (1,0.8,5) -- plot[variable=\t,domain=1:0.8]
  (\t,{4/(5*\t)},5) -- (0.8,1,5) --  (0,1,5) -- (0,0,5) -- cycle;
  \addplot3[surf] {min(1/(1-x*y),5.2)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • any importance of 1.6 instead of 1.8? – Jack Tiger Lam Jun 24 '19 at 15:04
  • @JackLam It is 1.16, and the answer is yes. In older versions you need to prepend the coordinates used in the clip path with axis cs:. – user121799 Jun 24 '19 at 15:06
  • Overleaf does not allow the use of 1.16. Do you have a workaround? – Jack Tiger Lam Jun 24 '19 at 15:13
  • @JackLam Try compat=newest. Most likely this will work, if not, use \clip (axis cs:0,0,0) -- (axis cs:1,0,0) -- (axis cs:1,0.8,0) -- (axis cs:1,0.8,5) -- plot[variable=\t,domain=1:0.8] (axis cs:\t,{4/(5*\t)},5) -- (axis cs:0.8,1,5) -- (axis cs:0,1,5) -- (axis cs:0,0,5) -- cycle;. – user121799 Jun 24 '19 at 15:15

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.