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/
201 stars 36 forks source link

Visual Artefact When Using `axis line style = {rounded corners}` #234

Open pgf-tikz-bot opened 4 years ago

pgf-tikz-bot commented 4 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/234/ Author: manuelkuehner Timestamp: 2020-02-04 12:21:10.720000

https://sourceforge.net/p/pgfplots/bugs/234/attachment/InkedScreenshot%202020-02-04%2020.19.49_LI.jpg

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
%
\begin{axis}[
    width = 20mm,
    height = 20mm,
    xmin = -1.2,
    xmax = 2.2,
    ymin = -1.3,
    ymax = 4.3,
    axis line style = {rounded corners = 5mm},
    scale only axis,
    ticks = none
    ]
\end{axis}
%
\end{tikzpicture}

\end{document}

This creates a additional line, see screenshot.

pgf-tikz-bot commented 4 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/234/#d557 Author: manuelkuehner Timestamp: 2020-02-04 12:22:13.100000

Origin of this topic is my answer at https://tex.stackexchange.com/questions/526852.

manuel-kuehner commented 1 year ago

Any chance to get some attention on this bug?

muzimuzhi commented 1 year ago
diff --git a/tex/generic/pgfplots/pgfplots.code.tex b/tex/generic/pgfplots/pgfplots.code.tex
index 0b4486b..b81ef66 100644
--- a/tex/generic/pgfplots/pgfplots.code.tex
+++ b/tex/generic/pgfplots/pgfplots.code.tex
@@ -5267,9 +5267,18 @@
    %{ (\pgfplots@xmin, \pgfplots@ymin) }
    { \pgfextra\pgfpathmoveto{\pgfplotsqpointxy{\pgfplots@xmin}{\pgfplots@ymin}}\endpgfextra }
 \else
-   decorate [xdiscont,decoration={pre length=\xdisend, post length=\xdisstart}]
-   %{ -- (\pgfplots@xmin,  \pgfplots@ymin) }
-   { \pgfextra\pgfpathlineto{\pgfplotsqpointxy{\pgfplots@xmin}{\pgfplots@ymin}}\endpgfextra }
+   \if0\pgfplots@xaxisdiscontnum\relax
+   \else
+       decorate [xdiscont,decoration={pre length=\xdisend, post length=\xdisstart}]
+       %{ -- (\pgfplots@xmin,  \pgfplots@ymin) }
+       { \pgfextra\pgfpathlineto{\pgfplotsqpointxy{\pgfplots@xmin}{\pgfplots@ymin}}\endpgfextra }
+       \if0\pgfplots@yaxisdiscontnum
+       \else
+           decorate [xdiscont,decoration={pre length=\xdisend, post length=\xdisstart}]
+           %{ -- (\pgfplots@xmin,  \pgfplots@ymin) }
+           { \pgfextra\pgfpathlineto{\pgfplotsqpointxy{\pgfplots@xmin}{\pgfplots@ymin}}\endpgfextra }
+       \fi
+   \fi
 \fi
    % make sure that we do not have any of the axis discontinuities
    % here - they should not be closed.

image

Full example used to generate the screenshot above

```tex \documentclass{article} \usepackage{pgfplots} \usepackage{xpatch} \makeatletter \def\patch{% \xpatchcmd\pgfplots@drawaxis@outerlines@cycledpath{% decorate [xdiscont,decoration={pre length=\xdisend, post length=\xdisstart}] %{ -- (\pgfplots@xmin, \pgfplots@ymin) } { \pgfextra\pgfpathlineto{\pgfplotsqpointxy{\pgfplots@xmin}{\pgfplots@ymin}}\endpgfextra } }{% \if0\pgfplots@xaxisdiscontnum\relax \else decorate [xdiscont,decoration={pre length=\xdisend, post length=\xdisstart}] %{ -- (\pgfplots@xmin, \pgfplots@ymin) } { \pgfextra\pgfpathlineto{\pgfplotsqpointxy{\pgfplots@xmin}{\pgfplots@ymin}}\endpgfextra } \if0\pgfplots@yaxisdiscontnum \else decorate [xdiscont,decoration={pre length=\xdisend, post length=\xdisstart}] %{ -- (\pgfplots@xmin, \pgfplots@ymin) } { \pgfextra\pgfpathlineto{\pgfplotsqpointxy{\pgfplots@xmin}{\pgfplots@ymin}}\endpgfextra } \fi \fi }{}{\PatchFailed} } \makeatother \def\test{ \begin{tikzpicture} \begin{axis}[ width = 20mm, height = 20mm, xmin = -1.2, xmax = 2.2, ymin = -1.3, ymax = 4.3, axis line style = {rounded corners=5mm}, scale only axis, ticks = none ] \end{axis} \end{tikzpicture} } \begin{document} Before \test % \patch After \test \end{document} ```

Briefly, this is the same difference between

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[rounded corners=3mm]
  \draw (0,0) -- ++(1,0) -- ++(0, 1) -- ++(-1,0) -- ++(0, -1) -- cycle;
  \draw[xshift=1.2cm] (0,0) -- ++(1,0) -- ++(0, 1) -- ++(-1,0) -- cycle;
\end{tikzpicture}
\end{document}

image

I recalled a similar problem was caught elsewhere. Rectangle path operation takes care of cycle, but the code here uses decorate option...

muzimuzhi commented 1 year ago

TODO: check if lines 5267--5268 need similar patch https://github.com/pgf-tikz/pgfplots/blob/a1fe88f619859de5f798ab4c095aeea40f6fad59/tex/generic/pgfplots/pgfplots.code.tex#L5266-L5284