tikzpicture 和 pdf - x 轴部分消失

tikzpicture 和 pdf - x 轴部分消失

我想知道为什么 x 轴会部分消失,给出以下代码。这是 PDF 问题吗?此外,是否有任何选项可以自动但不平滑地连接中点?

代码如下:

\documentclass[landscape]{article}

\usepackage{etex}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{tikz}

\usetikzlibrary{backgrounds,fadings}

\begin{document}

\begin{tikzpicture}%[show background grid]

\tikzstyle{every node}=[font=\scriptsize]

\begin{axis}[/tikz/ybar, 
ybar legend, 
xtick align=outside,
ymin=0,
axis y line*=left,
bar width=1.5cm,
axis x line*=left,
 nodes near coords= {
    \pgfmathfloattofixed{\pgfplotspointmeta} 
    \num[
        scientific-notation = fixed,
        fixed-exponent = 0,
        round-mode = places,
        round-precision = 2,
        exponent-product=\cdot
    ]{\pgfmathresult}},
enlarge x limits=false,
grid=none,   
height=6cm,
title={},
xlabel={Intervalos de Clase},
ylabel=\rotatebox{-90}{$F_{i}$},
symbolic x coords={$<11.5$,$11.5$,$14.5$,$17.5$,$20.5$,$23.5$,$>23.5$},
xtick={$11.5$,$14.5$,$17.5$,$20.5$,$23.5$},
minor x tick num=1, 
width=\textwidth]
\addplot[white,fill=white] coordinates {($<11.5$,0) ($>23.5$,0)};
\addplot[green!80!black,fill=green!40!white] coordinates {($11.5$,0.32)($14.5$,0.56)   ($17.5$,0.64) ($20.5$,0.76) ($23.5$,1.00)};
\addplot[thick,color=blue,line join=round, smooth] coordinates {($11.5$,0.32) ($14.5$,0.56) ($17.5$,0.64) ($20.5$,0.76) ($23.5$,1.00)};
\legend{}
\end{axis}
\end{tikzpicture}           

\begin{tikzpicture}[overlay]
\node[above] (red) at (0.8,2) {\footnotesize\textcolor{magenta}{Ojiva}};
\node (reddot) at (4.1,3.0) {};
\path[->, color=magenta, line width=0.75] (red) edge [out = 50, in = 145] (reddot);
\node[right] (gre) at (11.5,2.75) {\footnotesize\textcolor{cyan}{Histograma}};
\node (gredot) at (10,2.9) {};
\path[->, color=cyan, line width=0.75] (gre) edge [out = 160, in = 45] (gredot);
\end{tikzpicture}

\end{document}

答案1

轴线被打断了,因为您在轴线上方绘制了两个高度为零的条形图。要解决这个问题,一种方法是axis on top在选项中指定axis。这还将确保绿色条形图不会绘制在轴线上方。

看起来您只是使用这些空条来纠正间距。我建议不要这样做,而是使用键enlarge x limits在轴的左侧和右侧添加额外的空间。

要绘制由直线段组成的图,请使用sharp plot

\documentclass[landscape]{article}

\usepackage{etex}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{tikz}

\usetikzlibrary{backgrounds,fadings}

\begin{document}

\begin{tikzpicture}%[show background grid]

\tikzstyle{every node}=[font=\scriptsize]

\begin{axis}[/tikz/ybar, 
ybar legend, 
xtick align=outside,
ymin=0,
axis y line*=left,
bar width=1.5cm,
axis x line*=left,
 nodes near coords= {
    \pgfmathfloattofixed{\pgfplotspointmeta} 
    \num[
        scientific-notation = fixed,
        fixed-exponent = 0,
        round-mode = places,
        round-precision = 2,
        exponent-product=\cdot
    ]{\pgfmathresult}},
enlarge x limits=false,
grid=none,  
axis on top, 
height=6cm,
title={},
xlabel={Intervalos de Clase},
ylabel=\rotatebox{-90}{$F_{i}$},
symbolic x coords={$<11.5$,$11.5$,$14.5$,$17.5$,$20.5$,$23.5$,$>23.5$},
xtick={$11.5$,$14.5$,$17.5$,$20.5$,$23.5$},
minor x tick num=1, 
width=\textwidth]
\addplot[white,fill=white] coordinates {($<11.5$,0) ($>23.5$,0)};
\addplot[green!80!black,fill=green!40!white] coordinates {($11.5$,0.32)($14.5$,0.56)   ($17.5$,0.64) ($20.5$,0.76) ($23.5$,1.00)};
\addplot[thick,color=blue, sharp plot] coordinates {($11.5$,0.32) ($14.5$,0.56) ($17.5$,0.64) ($20.5$,0.76) ($23.5$,1.00)};
\legend{}
\end{axis}
\end{tikzpicture}           

\begin{tikzpicture}[overlay]
\node[above] (red) at (0.8,2) {\footnotesize\textcolor{magenta}{Ojiva}};
\node (reddot) at (4.1,3.0) {};
\path[->, color=magenta, line width=0.75] (red) edge [out = 50, in = 145] (reddot);
\node[right] (gre) at (11.5,2.75) {\footnotesize\textcolor{cyan}{Histograma}};
\node (gredot) at (10,2.9) {};
\path[->, color=cyan, line width=0.75] (gre) edge [out = 160, in = 45] (gredot);
\end{tikzpicture}

\end{document}

相关内容