1

I need to do a graph with horizontal bars, that give the period of plantation of each Field i, i=1,...,10. I have the following code:

\documentclass[12pt,fleqn]{article}

\usepackage{a4wide}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage[dvips]{epsfig}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[numbers]{natbib}
\usepackage{fancybox}
\usepackage{longtable}
\usepackage{rotating}
\usepackage{supertabular}
\usepackage{multirow}
\usepackage[usenames]{color}
\usepackage{natbib}
\usepackage{setspace}
\usepackage[usenames]{color}
\usepackage[normalem]{ulem}
\usepackage{pgfplots}


\usepackage{tikz,tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{arrows}
\usepackage{amsmath}
\usetikzlibrary{quotes,angles}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{shapes,shadings}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{polar}
\usetikzlibrary{decorations.pathreplacing}

\usepackage{subfigure}

\renewcommand{\baselinestretch}{1.3}  %1.6 = double line spacing
\newcommand{\Sum}{\sum\limits_}
\newtheorem{proposition}{Proposition}

% Set A4 size (very important because the default size is wider)
\paperwidth=8.3in
\paperheight=11.7in

\usepackage{array}
\usepackage{xparse}
\usepackage{pgfplots}

\ExplSyntaxOn
\NewDocumentCommand{\newlistcommand}{mm}
 {
  \NewDocumentCommand{#1}{m}
   {
    \clist_set:Nn \l_xaero_args_clist { ##1 }
    #2
   }
 }
\NewExpandableDocumentCommand{\argx}{m}
 {
  \clist_item:Nn \l_xaero_args_clist { #1 }
 }
\ExplSyntaxOff

\newlistcommand{\graficobarras}{%
  \begin{tikzpicture}
  \pgfplotsset{compat=1.12}
    \begin{axis}[
        xmin=-2,xmax=29,
        tickwidth         = 5pt,
        ymax=11,
        width=15cm,
        height=10cm,
        axis y line=left,
        axis x line=bottom,
        ymin=0,
        xmajorgrids=true,
            nodes near coords,
        xlabel={Days},
        xticklabels={-2,0,2,4,...,30},
        ytick={1,2,...,10,12},
        yticklabels={Field 1,Field 2,Field 3,Field 4,Field 5,Field 6,Field 7,Field 8,
             Field 9,Field 10,}
        ]
      \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{1},1) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{2},1)node[right,yshift=-2.5mm,text=black]{\argx{21}};               
       \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{3},2) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{4},2)node[right,yshift=-2.5mm,text=black]{\argx{22}};               
       \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{5},3) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{6},3)node[right,yshift=-2.5mm,text=black]{\argx{23}};               
       \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{7},4) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{8},4)node[right,yshift=-2.5mm,text=black]{\argx{24}};               
       \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{9},5) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{10},5)node[right,yshift=-2.5mm,text=black]{\argx{25}};               
       \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{11},6) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{12},6)node[right,yshift=-2.5mm,text=black]{\argx{26}};               
       \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{13},7) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{14},7)node[right,yshift=-2.5mm,text=black]{\argx{27}};               
       \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{15},8) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{16},8)node[right,yshift=-2.5mm,text=black]{\argx{28}};               
       \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{17},9) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{18},9)node[right,yshift=-2.5mm,text=black]{\argx{29}};               
       \filldraw[blue!40,draw=black] ([yshift=-2.5mm,xshift=-0.85cm]\argx{19},10) rectangle
               ([yshift=2.5mm,xshift=-0.85cm]\argx{20},10)node[right,yshift=-2.5mm,text=black]{\argx{30}};
    \end{axis}
  \end{tikzpicture}
}

\allowdisplaybreaks[1] %to allow automatic page breaks for formulas written with \alignat


\begin{document}

\graficobarras{1,7,10,17,2,9,25,30,16,22,24,30,7,16,5,24,23,30,18,24,9.87,11.32,10.67,11.39,14.44,13.70,10.65,7.07,14.32,11.32}

\end{document}

Each field has a planting period. My problem is when I need to insert the number at right of last bar. Don't appear. I wouldn't to increase the parameter "xmax" to 31, because the grid also increase. There is a way to increase te size the figure, without to cut the nodes numbers? This code generates the following picture: enter image description here Best regards.

  • Could you turn your code into a complete example that we can compile without any modifications? \argx and \graficobarras are not defined by default. Also, note that you can edit your question, so please add the image to the question, instead of posting it in an answer. – Torbjørn T. Apr 7 at 15:41
  • That said, add clip=false to the axis options. – Torbjørn T. Apr 7 at 15:46
  • Yes, I have done this modification, so you can to compile this figure. – Angelo Aliano Filho Apr 7 at 16:09
2

Simply add clip=false to the options of the axis in the definition of \graficobarras.

By default any paths, nodes etc. created by normal TikZ macros like \filldraw are clipped if they extend outside the axis limits. clip=false turns off that behaviour.

Unrelated note: you could tidy up the preamble a bit, you're loading several packages multiple times, which is unnecessary. Note also that the a4wide package is considered deprecated, it would be better to use the features of the geometry package.

| improve this answer | |

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.