条形图的问题

条形图的问题

我需要制作一个带有水平条的图表,给出每个田地 i 的种植期,i=1,...,10。我有以下代码:

\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}

每块田地都有一个种植期。我的问题是当我需要在最后一栏的右侧插入数字时。没有出现。我不想将参数“xmax”增加到 31,因为网格也会增加。有没有办法增加图形的大小,而不减少节点数?此代码生成以下图片: 在此处输入图片描述 此致。

答案1

只需在 的定义中添加clip=false的选项即可。axis\graficobarras

默认情况下,任何由普通 TikZ 宏创建的路径、节点等\filldraw如果超出轴限制都会被剪裁。clip=false关闭该行为。

无关注释:您可以稍微整理一下序言,您正在多次加载多个包,这是不必要的。还请注意,该a4wide包被视为已弃用,最好使用该geometry包的功能。

相关内容