4

Update :- This appears to be a problem in which nodes near coords are handled by PGFPlots and incompatibility with Tikz decorations and fading library. I simply commented the nodes near coords line and I got squiggly lines in the top graph and no errors. However, I would still like to know in future, how to use nodes near coords while using decorations. I am still not sure if this constitutes a bug report though.

Original Problem:- I would like to decorate a bar graph in PGFPlots using Tikz decorations library. I find that when I try to decorate it with say zigzag or snake or random steps, it throws an error. This seems specific to bar graphs though. I went to my original data and I tried to decorate a similar data in Histogram plot (Histogram distribution itself is calculated in PGFPlots from raw data), wherein I took the original dataset, used PGFPlots to draw the histogram plot and used Tikz to decorate. To my amazement if I used PGFPlots to calculate the histogram, the options seem to be different than when I use a bar graph on preprocessed data. I would like to decorate the bar graph shown in top figure similar to line edges shown in bottom figure. I have attached the code that generates both. How could I do that?

\documentclass[12pt]{article}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[margin=1cm]{geometry}
\usepackage{pgfplots}
\usetikzlibrary{patterns,fadings}

\begin{filecontents*}{Total_Histogram.dat}
 0.00000000e+00 2.00000000e+00
 5.00000000e-01 0.00000000e+00
 1.00000000e+00 3.00000000e+00
 1.50000000e+00 3.00000000e+00
 2.00000000e+00 4.00000000e+00
 2.50000000e+00 1.00000000e+00
 3.00000000e+00 2.00000000e+00
 3.50000000e+00 1.00000000e+00
 4.00000000e+00 2.00000000e+00
 4.50000000e+00 2.00000000e+00
 5.00000000e+00 3.00000000e+00
 5.50000000e+00 5.00000000e+00
 6.00000000e+00 3.00000000e+00
 6.50000000e+00 4.00000000e+00
 7.00000000e+00 7.00000000e+00
 7.50000000e+00 5.00000000e+00
 8.00000000e+00 4.00000000e+00
 8.50000000e+00 0.00000000e+00
 9.00000000e+00 2.00000000e+00
 9.50000000e+00 2.00000000e+00
 1.00000000e+01 1.00000000e+00
 1.05000000e+01 0.00000000e+00
 1.10000000e+01 3.00000000e+00
 1.15000000e+01 2.00000000e+00
 1.20000000e+01 0.00000000e+00
 1.25000000e+01 0.00000000e+00
 1.30000000e+01 1.00000000e+00
 1.35000000e+01 0.00000000e+00
 1.40000000e+01 0.00000000e+00
 1.45000000e+01 0.00000000e+00
 1.50000000e+01 0.00000000e+00
\end{filecontents*}

\begin{filecontents*}{Quiz1_Data_EE1100_Spring2014.txt}
0   1   1   0   3   4   9
0   0   0   0.5 1.5 2.5 4.5
1   1   0   0   1.5 2.5 6
0   0   0   0   1.5 4   5.5
1   1   1   1   3   4   11
1   1   0   0   0   1   3
1   0.5 0   0   3   0   4.5
1   0.5 0   0   0   0   1.5
1   1   1   0   3   4   10
1   0   1   1   0   4   7
1   1   0   0   1.5 6   9.5
1   0   0   0.5 1.5 4   7
1   0   0   0   1.5 4.5 7
0   0   1   0.5 1.5 2   5
1   0   0   0.5 3   1.5 6
1   1   1   1   3   6   13
1   1   0   0   0   6   8
0   0   0   0   0   0   0
0   1   1   1   1.5 1   5.5
0   1   0   0.5 3   7   11.5
1   1   1   0.5 3   1   7.5
1   1   0   0   1.5 2   5.5
1   0   0   0.5 1.5 1   4
1   1   1   1   2   1   7
1   0   1   0   1.5 2   5.5
1   0   1   0   3   3   8
1   0   0   0   0   1   2
1   1   0   0.5 1.5 3   7
1   1   1   0.5 3   1   7.5
0   1   1   0.5 3   2   7.5
1   1   0   0   1.5 8   11.5
1   0   0   0   0   0   1
0   0   1   0   3   1   5
1   1   0   0.5 3   2   7.5
0   1   0   0   1.5 0   2.5
1   1   0   0.5 3   1   6.5
1   1   1   1   3   4   11
1   1   1   0   1.5 5   9.5
1   1   1   0.5 1.5 3   8
1   0   0   0.5 0   2   3.5
1   0   1   0   1.5 3   6.5
0   1   1   1   3   3   9
1   0   0   0   0   1   2
1   0   1   0   1.5 3   6.5
1   1   0   0.5 0   1.5 4
1   1   1   0   0   4   7
0   0   0   0   1.5 0   1.5
1   1   1   0.5 1.5 6   11
1   1   1   0.5 1.5 3   8
0   0   0   0   0   0   0
1   1   0   0.5 3   1   6.5
1   1   1   0   0   4   7
0   1   0   0   0   0   1
1   0   1   0   0   0   2
1   0   0   0   0   4   5
0   1   0   0.5 1.5 0   3
0   1   0   0   0   0   1
1   0   0   0   0   1   2
1   0   1   0   1.5 2   5.5
1   0   1   0   0   4   6
1   1   1   0   1.5 3   7.5
0   0   0   0.5 0   1   1.5
\end{filecontents*}


\begin{document}
\pagestyle{empty}

\begin{tikzpicture}
    \centering
    \begin{axis}
    [
    width=\textwidth,
    ybar,
    ymin=0,
    xtick=data,
    xticklabel style={rotate=45},
    legend columns=-1,
    nodes near coords,
    every node near coord/.append style={
    rotate=30,
    xshift=1mm,
    inner sep=1pt,
    color=gray
    },
    ytick={0,1,2,3,4,5,6,7},
    ymajorgrids,
    major grid style={thick,white},
    axis on top,
    tick pos=left,
    xlabel=Total Points in Quiz-1,
    ylabel=Number of Students,
    x label style={at={(axis description cs:0.5,-0.05)},anchor=north},
    title={\bf Performance of students in Quiz-1}
    ]

        \addplot+[color=red!30,draw=black,forget plot] table [y index=1,x index=0,skip coords between index={5}{31}]{Total_Histogram.dat};
        \addplot+[color=yellow!30,draw=black,forget plot] table [y index=1,x index=0,skip coords between index={0}{5},skip coords between index={11}{31}]{Total_Histogram.dat};
        \addplot+[color=blue!30,draw=black,forget plot] table [y index=1,x index=0,skip coords between index={0}{11},skip coords between index={17}{31}]{Total_Histogram.dat};
        \addplot+[color=green!30,draw=black] table [y index=1,x index=0,skip coords between index={0}{17}]{Total_Histogram.dat};

        \node [fill=red!30,,decoration={random steps,segment length=6pt,amplitude=2pt},decorate] at (axis cs:0.65,3.75) {Attention};
        \node [fill=yellow!30] at (axis cs:3.5,3.75) {C,D grades};
        \node [fill=blue!30] at (axis cs:7,7.35) {B grade};
        \node [fill=green!30] at (axis cs:11,3.75) {A,S grades};
        \draw [->,blue,ultra thick] (axis cs:5.9,0) -- (axis cs:5.9,6.5) node [anchor=north east,draw=gray,xshift=-1.5mm]{Average=5.9};
        \draw [<->,gray,ultra thick]    (axis cs:-0.1,5.4) -- (axis cs:5.8,5.4) node [anchor=north,midway]{28 Students};
        \draw [<->,gray,ultra thick]    (axis cs:6.0,5.4) -- (axis cs:15,5.4) node [anchor=north,midway]{34 Students};
    \end{axis}

\end{tikzpicture}

\tikzfading[name=middle,
        top color=transparent!20,
        bottom color=transparent!20,
        middle color=transparent!50]

\begin{tikzpicture}[path fading=middle]
    \begin{axis}[
    width=\textwidth,
    ymin=0,
    title=Quiz-1 Total Points,
    xtick=data,
    x tick label style = {rotate=45},
    ybar interval,
    xtick align=outside,
    xmajorgrids=false,
    enlarge x limits=false,
    ymajorgrids=true,
    xlabel=Total points obtained,
    ylabel=Number of Students,ytick=data,
    x label style={at={(axis description cs:0.5,-0.05)},anchor=north},
    thick
    ]

    \addplot+[hist={bins=3,data min=0,data max=1.5},decorate,draw=black,path fading,fill=green!20,decoration={random steps,segment length=6pt,amplitude=1pt}] table [y index=1] {Quiz1_Data_EE1100_Spring2014.txt};
    \addplot+[hist={bins=3,data min=0,data max=1.5},decorate,draw=black,path fading,decoration={random steps,segment length=6pt,amplitude=1pt}] table [y index=2] {Quiz1_Data_EE1100_Spring2014.txt};
    \addplot+[hist={bins=3,data min=0,data max=1.5},decorate,draw=black,path fading,decoration={random steps,segment length=6pt,amplitude=1pt}] table [y index=3] {Quiz1_Data_EE1100_Spring2014.txt};
    \addplot+[hist={bins=3,data min=0,data max=1.5},decorate,draw=black,path fading,decoration={random steps,segment length=6pt,amplitude=1pt}] table [y index=4] {Quiz1_Data_EE1100_Spring2014.txt};
    \end{axis}

\end{tikzpicture}

\end{document}

Bar graph to be decorated

Histogram decorated by PGFPlots

By Commenting Nodes near coords and adding decorations, I get the following image:- Squiggly lines

However, now I cannot use nodes near coords any more.

7
  • Sorry, I don't understand By Commenting Nodes near coords and adding decorations. How did you get last figure, i.e bar with decorations?
    – user31034
    Mar 11, 2014 at 13:54
  • @ferahfeza if you notice the first figure, there are nodes near coords that is, every bar has got a number on the top. In the last figure, I added the keyword decorate and decoration type, however the compiler threw an error. If I commented nodes near coords line, then the last figure is obtained. This is probably a bug wherein PGFPlots does not process nodes near coords correctly with Tikz decorations or fadings turned on.
    – anakrich
    Mar 11, 2014 at 17:00
  • Please give the tikzpicture code part for the last figure.
    – user31034
    Mar 11, 2014 at 17:36
  • 1
    @anakrich Is your problem solved with an package update?
    – Bobyandbob
    Feb 9, 2018 at 21:26
  • 5
    I'm voting to close this question as off-topic because a package update solved the problem.
    – Bobyandbob
    Mar 26, 2018 at 16:46

0

Browse other questions tagged .