1

I am creating histogram graphs using pgfplots and tikz. I have used tikz for other figures, but never a graph.

The code I am running is:

\documentclass[oneside,12pt,openany,fleqn]{article}

\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[
        ymin=0, ymax=12,
        minor y tick num = 3,
        area style,
        ]
        \addplot+[ybar interval,mark=no] plot coordinates { (0, 1) (5, 0) (10, 0) (15, 0) (20, 0) (25, 0) (30, 1) (35, 2) (40, 2) (45, 5) (50, 7) (55, 6) (60, 10) (65, 10) (70, 6) (75, 9) (80, 2) (85, 1) (90, 3) (95, 1) };
    \end{axis}
\end{tikzpicture}
\caption[A1 Average of Classcraft Participants]{A1 Average of Classcraft Participants}
\label{fig:players-A1-average}
\end{figure}
\end{document}

and the figure looks like the image.enter image description here

I am very happy with how it looks, all I want is to adjust the scale of the x-axis so that all the numerical values I gave for the x-coordinates are displayed.

Can someone please help with this?

5
  • 1
    Please make your code compilable. tex.meta.stackexchange.com/questions/228/… Commented Nov 17, 2020 at 12:11
  • I think I just fixed it. I am not sure how to make it like other people who have posted. Commented Nov 17, 2020 at 12:20
  • 1
    You need to make it compilable - starting with \documentclass{article} and ending with \end{document} Commented Nov 17, 2020 at 12:28
  • 1
    The smallest x value you give is 0 and the largest is 95. -so they are all there!! Do you want more numbers on the the x axis like 0,5,10,15,...? -or do you want the graph stretched wider? -or more ticks(the small lines)? Commented Nov 17, 2020 at 12:46
  • The first way you mentioned, I want the increments of 5 (0,5,10,15,...) to display on the axis. If the graph can be stretched wider that would be preferable also. Commented Nov 17, 2020 at 12:57

1 Answer 1

4

With so many numbers(xtick distance=5) on the x axis, you also need a wider graph to make room for them e.g. like this:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width=\textwidth,
        height=7cm,
        xmin=0, xmax=100,
        ymin=0, ymax=12,
        xtick distance=5,
        minor y tick num = 3,
        area style,
    ]
    \addplot+[ybar interval] plot coordinates { (0, 1) (5, 0) (10, 0) (15, 0) (20, 0) (25, 0) (30, 1) (35, 2) (40, 2) (45, 5) (50, 7) (55, 6) (60, 10) (65, 10) (70, 6) (75, 9) (80, 2) (85, 1) (90, 3) (95, 1) };
\end{axis}
\end{tikzpicture}
\end{document}

Graph

1
  • Awesome! That is perfect. Thank you very much! Commented Nov 17, 2020 at 13:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .