# Why does \psplot need higher plotpoints when plotting a function on the left of the function's asymptote?

The following animation shows the behavior intuitively. \psplot seems to work in an asymmetric way. It can plot the right part with the default plotpoints but it is not the case when it plots the left part. We need to increase the plotpoints to obtain the complete graph on the left part.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

\pstVerb{/myDiv {dup 0 eq {pop 0 lt {-1e30} {1e30} ifelse} {div} ifelse} def}

\def\f#1{1 #1 myDiv}
\def\g#1{\f{#1 neg}}

\psset{yMinValue=-4,yMaxValue=4}

\begin{document}
\multido{\i=7+12}{20}{%
\psset{plotpoints=\i}
\begin{pspicture}[showgrid=bottom](-2,-4)(2,4)
\psclip{\psframe[linestyle=none,dimen=middle](-2,-4)(2,4)}
\psplot[linecolor=red]{-2}{2}{\f{x}}
\psplot[linecolor=blue]{-2}{2}{\g{x}}
\rput(0,0){\textcolor{red}{plotpoints: \i}}
\endpsclip
\end{pspicture}}
\end{document}


Why does \psplot need higher plotpoints when plotting a function on the left of the function's asymptote? Is it a bug?

-
you are plotting one function with a vertical asymptote in it. on the left the last line segment is plotted to (x|y<MaxValue) on the right the first line is plotted from (x|y>MaxValue) to (x|y<MaxValue). That is different to the plotstyle dots where you get a symmetrical behaviour. –  Herbert Aug 24 '12 at 9:51
@Herbert: Is it a good idea to add an option to \psplot to specify the asymptote x=a such that the \psplot can choose the correct starting points for both sides around the asymptote line? –  cyanide-based food Aug 24 '12 at 9:59
in general yes, but at the moment too much work ... –  Herbert Aug 24 '12 at 10:03

for an even number of plotpoints the x values are not symmetrical to the y axis, the reason why you didn't reach the not allowed division by zero 1/0 but have not the same distance of the points from the y axis. Choosing an odd number of plotpoints, eg 13, creates symmetrical x values but also has x=0 in the set. However, 1/0 can be catched by an own division operator and plotpoints=6*n+1 with n=1,2,... will give a symmetrical behaviour for this kind of function.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

\begin{document}
\pstVerb{ % control the division, y x is on the stack
/myDiv { dup 0 eq { pop 0 lt { -1e30 }
{  1e30 } ifelse }
{ div } ifelse } def
}

\psset{plotpoints=24,plotstyle=dots}
\begin{pspicture}[showgrid=bottom](-2,-5)(4,5)
\psplot[linecolor=red]{-2}{4}{1 x myDiv}
\psplot[linecolor=blue]{-2}{4}{-1 x myDiv}
\end{pspicture}

\psset{plotpoints=25,plotstyle=dots}
\begin{pspicture}[showgrid=bottom](-2,-5)(4,5)
\psplot[linecolor=red]{-2}{4}{1 x myDiv}
\psplot[linecolor=blue]{-2}{4}{-1 x myDiv}
\end{pspicture}

\psset{plotpoints=241,plotstyle=line,yMaxValue=5}
\begin{pspicture}[showgrid=bottom](-2,-5)(4,5)
\psplot[linecolor=red]{-2}{4}{1 x myDiv}
\psplot[linecolor=blue]{-2}{4}{-1 x myDiv}
\end{pspicture}

\end{document}


-
Is 1e30 the maximum value allowed in PS? –  cyanide-based food Aug 24 '12 at 8:44
that is the value accepted by all PS levels –  Herbert Aug 24 '12 at 8:47
If we gradually increase plotpoints for the last pspicture with plotstyle=line, the graph is actually still asymmetric for the first several plotpoints and it reaches the steady state later. –  cyanide-based food Aug 24 '12 at 9:04
sure, only the |y| < yMaxValue are plotted, there is no interpolation –  Herbert Aug 24 '12 at 9:26
I still don't understand why plotstyle=dots always produces a symmetric result but plotstyle=line does not. In my mental model, plotstyle=line should be symmetric as well if it uses the same dots as plotstyle=dots does. –  cyanide-based food Aug 24 '12 at 9:45