6

I just occured a very strange problem with pgfplots. Consider this MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    domain=0:5,
    xmin=0, xmax=3,
    ymin=0, ymax=3.5,
    samples=500,
    width=11cm,
    height=6cm,
    axis y line=center,
    axis x line=middle,
    ytick={1},
    xtick={1}
    ]
    \addplot[red, very thick, mark=none] {x^2/sqrt((1-x^2)^2)};     
    \end{axis}
    \end{tikzpicture}
\end{document}

This renders like this (expectedly) in every PDF reader I tried:

render

But when I print it, it looks like this (scan):

print

I printed it on different machines, different printers and different Adobe Reader versions (Acrobat Reader XI Pro and Acrobat Reader DC). The result is always the same, so it's not a driver/printer issue. Printing from Firefox is fine, but since I'm working on lecture notes that are going to be printed by a lot of people, telling everyone "don't use Adobe Reader" is not a solution.

I just want to know why this happens and what I can do to avoid it.

(I know this is a bit hard to debug because it involves printing.)

I already tried to alter the plot and discovered that as soon as I added something to the denominator that made the definition gap disappear, not only the top horizontal line disappeared, but both bottom lines too. But it is not a general definition gap problem, I have other plots with some and they are printed fine.

  • Have you tried any other pdf reader? (Except adobe). It could be a adobe bug if other pdf readers doesn't cause this. – koleygr Sep 25 '17 at 22:22
  • Yes, as I said, I printed it with firefox and it looks fine. However, I guess Adobe Reader doesn't simply print something that is not there (and it looks like the path was just closed wherever possible), and even if, there must be a solution that works with Adobe Reader too. – jaytar Sep 25 '17 at 22:26
  • 1
    Though you said it's not, this looks like a printer driver problem as PostScript operation does not lift the pen. Does it happen if you change the axis limits? – percusse Sep 25 '17 at 22:32
  • Firefox uses some extensions for pdf but it is not really a pdf reader... just includes extensions... If only adobe and not other pdf readers has the problem it is off-topic here. It is a problem to be reported at adobe's bugs. Just try one or two other pdf viewers (there ate many of them and many open source too). (Me and most of the people doesn't really know what adobe is looking for to print, since it is a closed source program.) – koleygr Sep 25 '17 at 22:35
  • 3
    How about the [restrict y to domain=0:10]? That is a more reasonable fix. – John Kormylo Sep 26 '17 at 19:56
3

I had a similar problem and found the following solution to do the trick: add restrict x to domain = 0:10 and restrict y to = 0:10 to your axis environment. The domain range should be chosen such that the full range of your plot is inculded. e.g. if you want to plot from (0:0) to (2:2) chose the domain from -1 to 3 so that the borders on the axes are plotted as well. Your MWE hence would look like this:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    domain=0:5,
    xmin=0, xmax=3,
    ymin=0, ymax=3.5,
    samples=500,
    width=11cm,
    height=6cm,
    axis y line=center,
    axis x line=middle,
    ytick={1},
    xtick={1},
    restrict x to domain = 0:4,
    restrict y to domain = 0:4
    ]
    \addplot[red, very thick, mark=none] {x^2/sqrt((1-x^2)^2)};     
    \end{axis}
    \end{tikzpicture}
\end{document}
  • 2
    This was already suggested by John Kormylo in the comment below the question already, but OP didn't comment on that so far ... – Stefan Pinnow Feb 12 '18 at 18:51
  • Is there a way to know if I would experience this behaviour without printing? – Paul Lara Apr 14 '18 at 13:21
  • In my case the problem also occurred when I printed it to pdf. – nmy2015 Apr 15 '18 at 14:28

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.