pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.
http://pgfplots.sourceforge.net/
187 stars 33 forks source link

Printing problem using Adobe Reader #438

Open aybed opened 2 years ago

aybed commented 2 years ago

I am using PGFPLOTS to produce plots in my thesis. When I print out the document using Adobe Reader, some additional weird lines appears (in small box) in some plots (not all) created by using PGFPLOTS. There is no problem when I use different PDF readers (Foxit, Sumatra, web browsers like Chrome etc.) to print out. I have realized some other people have the same problem, and all it is related to Adobe Reader. However, I couldn't find any solution. As a matter of fact, if someone using adobe prints the document, plots will be printed incorrectly. To compare, I am attaching the printed paper and the real plot. I am using the newest version. \pgfplotsset{compat=1.18}. I need your help, thank you all.

My latex code

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{external}
\tikzexternalize[prefix=TikzPDFs/,shell escape=-enable-write18]
\usepackage{color}

\begin{document}
\begin{figure}[h]
    \pgfplotsset{
        width=14cm,
        height=8.5cm,
        table/search path={plt_files/bst_0model_dat},
        every axis plot/.append style={
        line width=0.9pt,
        },
        legend style={font=\footnotesize},
    }

\tikzsetnextfilename{bst_0model}
\begin{tikzpicture}
\begin{axis}[
mark options={solid,scale=1},
axis background/.style={fill=white},
xmin = 0, 
ymin = 0,
xmax=10,
ymax=90,
xlabel={Strain \%},
ylabel={Stress (MPa)},
legend cell align={left},
legend entries={Analytical Solution,m=0.0005,m=0.001,m=0.01,m=0.045},
legend pos=south east
]

\addplot [
smooth,red,
mark=Mercedes star flipped,
mark repeat=30,
mark size=2pt,
] table {analytical.dat};

\addplot [
solid,
smooth,green,
mark=star,
mark repeat=30,
mark size=1.8pt,
] table {m00005.dat};

\addplot [
solid,
smooth,blue,
mark=*,
mark repeat=30,
mark size=1.2pt,
] table {m0001.dat};

\addplot [
solid,
smooth,darkgray,
mark=square*,
mark repeat=30,
mark size=1pt,
] table {m001.dat};

\addplot [
solid,
smooth,orange,
mark=triangle*,
mark repeat=30,
mark size=1.8pt,
] table {m0045.dat};

\draw[->,-stealth] (axis cs:5,83) -- (axis cs:5,50);
\coordinate (insetPosition) at (rel axis cs:0.45,0.01);
 \end{axis}

\begin{axis}[ at={(insetPosition)},anchor={outer south east},
footnotesize,
mark options={solid,scale=1},
axis background/.style={fill=white},
xmin = 9.8, 
ymin =62.2,
xmax=10,
ymax=62.7,
xtick distance=0.1,
width=4cm
]

\addplot [
smooth,red,
mark=Mercedes star flipped,
mark repeat=10,
mark size=2pt,
] table {analytical.dat};

\addplot [
solid,
smooth,green,
mark=star,
mark repeat=5,
mark size=1.8pt,
] table {m00005.dat};

\addplot [
solid,
smooth,blue,
mark=*,
mark repeat=5,
mark size=1.2pt,
] table {m0001.dat};

\addplot [
solid,
smooth,darkgray,
mark=square*,
mark repeat=15,
mark size=1pt,
] table {m001.dat};

\addplot [
solid,
smooth,orange,
mark=triangle*,
mark repeat=20,
mark size=1.8pt,
] table {m0045.dat};

    \end{axis}
\end{tikzpicture}%
\end{figure}
\end{document}`

What I want : org

What printed out: WhatsApp Image 2022-06-04 at 3 27 27 PM

I marked weird lines with a red circle: WhatsApp Image 2022-06-04 at 3 27 27 PM (1)

ilayn commented 2 years ago

Please add the offending code here too.

aybed commented 2 years ago

Please add the offending code here too.

Sir, I added.

aybed commented 2 years ago

First of all, thank you for your effort to find a solution. I made the code much simpler and tried again. The same problem is exist ( weird additional line in printed document). Once again I realized that the problem is not related to data but related to printing using Adobe reader. I should also mention that I tried it on 2 different printers. Thank you all

The simplified code (NOW it is reproducible):

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{external}
\tikzexternalize[prefix=TikzPDFs/,shell escape=-enable-write18]
\usepackage{color}

\begin{document}
\begin{figure}[h]
    \pgfplotsset{
        width=14cm,
        height=8.5cm,
        every axis plot/.append style={
        line width=0.9pt,
        },
        legend style={font=\footnotesize},
    }

\tikzsetnextfilename{bst_0model}
\begin{tikzpicture}
\begin{axis}[
mark options={solid,scale=1},
axis background/.style={fill=white},
xmin = 0, 
ymin = 0,
xmax=10,
ymax=90,
xlabel={Strain \%},
ylabel={Stress (MPa)},
legend cell align={left},
legend entries={Analytical Solution},
legend pos=south east
]

\addplot [
red,
mark=*,
mark size=2pt,
]coordinates {
(0,0)
(2,62.3)
(10,62.3)
};

\coordinate (insetPosition) at (rel axis cs:0.45,0.01);
 \end{axis}

\begin{axis}[ at={(insetPosition)},anchor={outer south east},
footnotesize,
mark options={solid,scale=1},
axis background/.style={fill=white},
xmin = 9.8, 
ymin =62,
xmax=10,
ymax=62.5,
xtick distance=0.1,
width=4cm
]

\addplot [
red,
mark=*,
mark size=2pt,
]coordinates {
(0,0)
(2,62.3)
(10,62.3)
};

\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

What I see in PDF viewer: asdfafdads

What printed out (by using Adobe READER): WhatsApp Image 2022-06-04 at 11 12 29 PM

aybed commented 2 years ago

A similar problem without an exact solution: printing plot adds strange line

ilayn commented 2 years ago

I didn't look into it deeply but it seems to me that the issue comes from nesting plots. What I mean is this structure:

begin{axis}[...]
\addplot ...
\addplot ...
    \begin{axis}[...]
        \addplot ...
        \addplot ...
    \end{axis}
\end{axis}

Instead you might want to use separate axis environments and place it on top of it.

\begin{tikzpicture}
begin{axis}[...]
\addplot ...
\addplot ...
\end{axis}
# Do the second axis
\begin{axis}[at=<some place in the tikzpicture>]
    \addplot ...
    \addplot ...
\end{axis}
\end{tikzpicture}

That way I think the strange low-level interaction will go away. You can address the location if you label the first axis environment and do the placing relative to it, say, at=({[shift=(1cm, 2cm)]firstaxis.center)})

aybed commented 2 years ago

Sir, Thank you for your help. But I'm actually doing exactly as you suggested. I am concluding the first axis environment before beginning the second one.

ilayn commented 2 years ago

Ah yes you are right, sorry for the noise. Missed the \end{axis} part.

ilayn commented 2 years ago

I see my comment under the question indeed looks like the pen is not lifted. That is to say, it is connecting the final data point to origin for some reason in the print which points to a low-level driver issue. The answer given to the TeX.SX question deliberately removes the last point.

So I don't have a solution but you can add a dummy plotting command at the end of the addplot, say, -- +(0.5mm, 0cm) to force the addplot to finish the pen instruction. Apologies for not remembering all the command names, it's been some time now. But the idea is to finish off the plot instruction at the last point. Either by domain restriction or using a mini-hack as I mentioned until smarter people than myself will dig into the driver.

aybed commented 2 years ago

Sir thank you for your smart solution. I have added another last point which is far away from the domain ( for my case: (11, 62.3)). Then, I tried your solution and I was able to get a printout using Adobe reader without any weird line. Thank you very much for your high interest and help.

ilayn commented 2 years ago

My pleasure, glad the issue is temporarily resolved. Interesting bug indeed.

muzimuzhi commented 2 years ago

Just by curiosity, do you know of any virtual printers that can reproduce the problem?

aybed commented 2 years ago

Sorry for late response. I came across the same problem with Foxit, Sumatra and chrome as well.