Haga que el gráfico de barras de tikzpicture vaya de 0 a 100

Haga que el gráfico de barras de tikzpicture vaya de 0 a 100

El gráfico de barras generado con el siguiente código está en el eje y, no comienza en 0 ni termina en 100. En cambio, muestra desde el mínimo hasta el máximo de mis números. ¿Cómo lo cambio para que muestre la escala de 0 a 100?

\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.10,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
symbolic x coords={Test1,Test2,Test3,Test4},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
]
\addplot coordinates {(Test1,40) (Test2,60) (Test3,30.1) (Test4,88.2)};
\addplot coordinates {(Test1,70) (Test2,89.1) (Test3,42.3) (Test4,71.2)};
\legend{Test one,Test two}
\end{axis}
\end{tikzpicture}

Respuesta1

Normalmente, solo necesitarías agregar ymax=100más axisopciones, pero como lo tienes, enlargelimitstambién debes deshabilitarlo para el eje y, cambiando de enlargelimitsa enlarge x limits.

Existen múltiples estrategias para evitar la superposición entre los números y las barras adyacentes; tres se ilustran en el siguiente código:

  1. Aumentando el espacio entre las barras, agregando bar shift=<length>a cada una \addplot.

  2. Aumentando el ancho de las barras.

  3. Reducir el tamaño de fuente de los números.

ingrese la descripción de la imagen aquí

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
%Increase the space between bars, by adding a bar shift to each addplot:
\begin{tikzpicture}
\begin{axis}[
ybar,ymax=100,
enlarge x limits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
symbolic x coords={Test1,Test2,Test3,Test4},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
]
\addplot +[bar shift=8pt] coordinates {(Test1,40) (Test2,60) (Test3,30.1) (Test4,88.2)};
\addplot +[bar shift=-8pt] coordinates {(Test1,70) (Test2,89.1) (Test3,42.3) (Test4,71.2)};
\legend{Test one,Test two}
\end{axis}
\end{tikzpicture}

%Make the bars wider:
\begin{tikzpicture}
\begin{axis}[
ybar,ymax=100,
enlarge x limits=0.2, % modified
bar width=18pt,  %%% <-------- added
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
symbolic x coords={Test1,Test2,Test3,Test4},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
]
\addplot coordinates {(Test1,40) (Test2,60) (Test3,30.1) (Test4,88.2)};
\addplot coordinates {(Test1,70) (Test2,89.1) (Test3,42.3) (Test4,71.2)};
\legend{Test one,Test two}
\end{axis}
\end{tikzpicture}


%Reduce the font size of the numbers:
\begin{tikzpicture}
\begin{axis}[
ybar,ymax=100,
enlarge x limits=0.2,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
symbolic x coords={Test1,Test2,Test3,Test4},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
every node near coord/.append style={font=\tiny}%%% <-------- added
]
\addplot coordinates {(Test1,40) (Test2,60) (Test3,30.1) (Test4,88.2)};
\addplot coordinates {(Test1,70) (Test2,89.1) (Test3,42.3) (Test4,71.2)};
\legend{Test one,Test two}
\end{axis}
\end{tikzpicture}
\end{document}

información relacionada