Search code examples
latextikzpgfplots

Latex: \closedcycle Package pgf Warning: No path specified that can be filled on input


In the following plot, I am getting a warning. I know it has to do something with the coordinates but can't solve it for sure. If anyone can guide me in the right direction, it would be really helpful.

Package pgf Warning: No path specified that can be filled on input line 55.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{float}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\title{StackExchange}
\author{M. Tahasanul Ibrahim}
\date{January 2022}

\begin{document}

    \begin{figure}[H]
        \centering
        \begin{tikzpicture}
            \begin{axis}
                [
                    % ybar,
                    % xmin=-1,xmax=10,
                    % ymin=0,ymax=18,
                    % xlabel={Data Value},
                    % ylabel={Occurrence/Frequency}]
                    xlabel= {Data Value}, 
                    ylabel= {Occurrence/Frequency},
                    enlarge x limits=0.1,
                    legend style={
                            at={(0.5,-0.15)},               
                            anchor=north,legend columns=-1
                    },
                    width=12.8cm,
                    height=8cm,
                    point meta={x*100},
                    symbolic x coords={0,1,2,3,4,5,6,7,8,9},
                    grid=both,
                    grid style={line width=.1pt, draw=gray!10},
                    major grid style={line width=.2pt,draw=gray!50},
                    % axis lines=middle,
                    minor tick num=5,
                    nodes near coords={$\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}$},
                ]
            \addplot+ [color=black, bottom color=green, top color=red] coordinates
                {
                    (0,1)
                    (1,5) 
                    (2,7) 
                    (3,12) 
                    (4,15)
                    (5,9) 
                    (6,7) 
                    (7,3) 
                    (8,0)
                    (9,1) 
                } \closedcycle;
            \end{axis}
        \end{tikzpicture}
        \caption{Area chart representing statistical data}
    \end{figure}

\end{document}

Solution

  • These warnings arise because you are not only filling this path, you are also drawing the markers and the label markers in the same step.

    If you decompose this into two separate steps, you can avoid the warnings:

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{tikz}
    \usepackage{float}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.18}
    
    \title{StackExchange}
    \author{M. Tahasanul Ibrahim}
    \date{January 2022}
    
    \begin{document}
    
        \begin{figure}[H]
            \centering
            \begin{tikzpicture}
                \begin{axis}
                    [
                        % ybar,
                        % xmin=-1,xmax=10,
                        % ymin=0,ymax=18,
                        % xlabel={Data Value},
                        % ylabel={Occurrence/Frequency}]
                        xlabel= {Data Value}, 
                        ylabel= {Occurrence/Frequency},
                        enlarge x limits=0.1,
                        legend style={
                                at={(0.5,-0.15)},               
                                anchor=north,legend columns=-1
                        },
                        width=12.8cm,
                        height=8cm,
                        point meta={x*100},
                        symbolic x coords={0,1,2,3,4,5,6,7,8,9},
                        grid=both,
                        grid style={line width=.1pt, draw=gray!10},
                        major grid style={line width=.2pt,draw=gray!50},
                        % axis lines=middle,
                        minor tick num=5,
    %                    nodes near coords={$\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}$},
                    ]
                \addplot [color=black, bottom color=green, top color=red] coordinates
                    {
                        (0,1)
                        (1,5) 
                        (2,7) 
                        (3,12) 
                        (4,15)
                        (5,9) 
                        (6,7) 
                        (7,3) 
                        (8,0)
                        (9,1) 
                    } \closedcycle;
                    
                \addplot+[black,mark=*,nodes near coords={$\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}$},] coordinates
                    {
                        (0,1)
                        (1,5) 
                        (2,7) 
                        (3,12) 
                        (4,15)
                        (5,9) 
                        (6,7) 
                        (7,3) 
                        (8,0)
                        (9,1) 
                    };                
                \end{axis}
            \end{tikzpicture}
            \caption{Area chart representing statistical data}
        \end{figure}
    
    \end{document}
    

    enter image description here