Search code examples
plotlatexbar-charttikz

Tikzpicture: enlarge cuts off the other side of the plot


I would like to put some text labels above my bars in my bar chart. In order to make space for them, I try to use enlarge limits, but it looks like it shifts my whole plot, cutting off the bottom. How could I solve this?

I attached the code, the original plot and the one with the row enlarge y limits uncommented.

\begin{tikzpicture}
\begin{axis}[
    xlabel = {loss},
    ylabel = {probability},
    enlarge x limits=0.2,
    %enlarge y limits={rel=0.2,upper},
    bar width = 16pt,
    width=14cm,
    height=8cm,
    xtick=data]
    \addplot[ybar,fill=white] coordinates {(-10,0.9) (0,0.095) (95,0.005)};
    \node[above] at (axis cs:-10,0.9) {$90\%$};
    \node[above] at (axis cs:0,0.095) {$9.5\%$};
    \node[above] at (axis cs:95,0.005) {$0.5\%$};
\end{axis}
\end{tikzpicture}
\end{figure}

original plot shifted plot


Solution

  • Okay, I just figured out I can get the desired effect using ymax: ymax=1.1

    solution