1
  1. I was getting the X-axis labels to be printed without spaces.
  2. There is an issue with legends, it is in the way of the delay values
  3. How do I keep the values horizontally and enlarge them for better viewing?

MWE:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\usepackage{caption}
\usepackage{mathtools}
\begin{document}
\thispagestyle{empty}
\pgfplotsset
 {
 compat=1.11,
 /pgfplots/ybar legend/.style={
 /pgfplots/legend image code/.code={%
 \draw[##1,/tikz/.cd,yshift=-0.25em]
 (0cm,0cm) rectangle (20pt,0.8em);},
 },
}
 \begin{figure}[h]
 \pgfplotstableread{
 %Proposed         %Sheng Lin
 0   43.5             127.6     
 1   15.2             39
 2   57.3             135.9
 }\dataset
 \begin{tikzpicture}
 \begin{axis}[
    ybar,
    bar width = 0.2,
    width=16cm,
    height=14cm,
    ymin=0,
    ymax=140,        
    ylabel={Delay in ps},
    xtick=data,
    xticklabels = 
    {
        \strut  Read 0
        \strut  Read 1
        \strut  Read 2
    },
    %xticklabel style={yshift=-10ex},
    major x tick style = {opacity=0},
    minor x tick num = 1,
    minor tick length=2ex,
    every node near coord/.append style=
    {
            anchor=west,
            rotate=90
    },
    legend entries={Delay of Proposed SRAM ,Delay of [1]},
    legend columns=3,
    legend style={draw=none,nodes={inner sep=3pt}},
    width=1.2\textwidth, 
    ]
  \addplot[draw=black,fill=blue!60, nodes near coords] table[x index=0,y index=1]    \dataset; %ano de 2013-2014
  \addplot[draw=black,fill=red!60, nodes near coords] table[x index=0,y index=2] \dataset; %ano de 2012-2013

  \end{axis}
  \end{tikzpicture}
  \captionsetup{justification=centerlast, margin=10ex, labelfont=sc, textfont=sc,   format=hang, labelformat=default, labelsep=endash, font=Large, name=Graph\,}


   \end{figure}

   \end{document}
  • Sorry, @HarishKumar. I was getting the X-axis labels to be printed without spaces. Also, there is an issue with legends. – Agrim Raghav Jan 24 '15 at 9:32
  • I am not able to upvote your comments, also what about point 3. – Agrim Raghav Jan 24 '15 at 9:37
1

You can control the postion of legend by at key as in

legend style={at={(0.5,1)},anchor=north,draw=none,nodes={inner sep=3pt}},   %% changed here

Adjust values in (0.5,1) as you wish.

You are missing the comma , as the separator in

xticklabels =
    {
        \strut  Read 0,     %% you need comma (,) at the end here and next 2 lines
        \strut  Read 1,
        \strut  Read 2,
    },

To keep the values horizontal, change 90 to 0 in

every node near coord/.append style=
    {
            anchor=south,  %% changed
            rotate=0       %% changed
    },

There were other minor mistakes/changes, which, I have commented in the code itself.

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.11}
\usepackage{caption}
\usepackage{mathtools}
\begin{document}
\thispagestyle{empty}
\pgfplotsset
 {
 /pgfplots/ybar legend/.style={
 /pgfplots/legend image code/.code={%
 \draw[##1,/tikz/.cd,yshift=-0.25em]
 (0cm,0cm) rectangle (20pt,0.8em);},
 },
}
\begin{figure}[h]
\pgfplotstableread{
%Proposed         %Sheng Lin
0   43.5             127.6
1   15.2             39
2   57.3             135.9
}\dataset
\begin{tikzpicture}
\begin{axis}[
    ybar,
    bar width = 1cm,
    width=\textwidth,                  %%% changed
%    height=14cm,                %% better not needed
    ymin=0,
    ymax=150,                    %% changed here
    ylabel={Delay in ps},
    xtick=data,
    xticklabels =
    {
        \strut  Read 0,     %% you need comma (,) at the end here and next 2 lines
        \strut  Read 1,
        \strut  Read 2,
    },
    %xticklabel style={yshift=-10ex},
    major x tick style = {opacity=0},
    minor x tick num = 1,
    minor tick length=2ex,
    every node near coord/.append style=
    {
            anchor=south,  %% changed
            rotate=0       %% changed
    },
    legend entries={Delay of Proposed SRAM, Delay of [1]},
    legend columns=2,      %% 2 instead of 3 here
    legend style={at={(0.5,1)},,anchor=north,draw=none,nodes={inner sep=3pt}},   %% changed here
%    width=1.2\textwidth,   Why second time?
    ]
  \addplot[draw=black,fill=blue!60, nodes near coords] table[x index=0,y index=1]    \dataset; %ano de 2013-2014
  \addplot[draw=black,fill=red!60, nodes near coords] table[x index=0,y index=2] \dataset; %ano de 2012-2013

  \end{axis}
  \end{tikzpicture}
  \captionsetup{justification=centerlast, margin=10ex, labelfont=sc, textfont=sc,   format=hang, labelformat=default, labelsep=endash, font=Large, name=Graph\,}


   \end{figure}

   \end{document}

enter image description here

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.