0

I have the following LaTeX code I wrote:

\begin{tikzpicture}
\begin{axis}[
    title={Execution Time Using Varying Array Sizes },
    xlabel={Array Length},
    ylabel={Execution Time [milliseconds]},
    xmin=0, xmax=1000000,
    ymin=0, ymax=30,
    xtick={0,1000,10000,100000,1000000},
    ytick={0,5,10,15,20,25,30},
    ymajorgrids=true,
    grid style=dashed,
]

\addplot[
    color=blue,
    mark=square,
    ]
    coordinates {
    (1000,4.1)(10000,4.2)(100000,6.6)(1000000,26.0)
    };

    
\end{axis}
\end{tikzpicture}

My problem is that the x-axis values don't show clearly, here is a picture that showcases it: problem

Any help in resolving this would be appreciated, I have already tried playing around with the code like doing things such as switching axis, etc...

6
  • You expect to see clearly your x ticks, but you chose a linear scale, which is not suitable for this kind of range (1000, 10000, 100000, 1000000).
    – SebGlav
    Commented Feb 15, 2021 at 15:43
  • Switch from your axis to a semilogxaxis environment. Therefore you show the first x values although they are very close to each other in comparison to the last one.
    – Venez
    Commented Feb 15, 2021 at 15:44
  • @SebGlav I have no idea how to change this to a logarithmic scale, thought it would do this on its own when seeing the vlaues
    – Sergio
    Commented Feb 15, 2021 at 15:47
  • @Venez I kept everything the same but changed \begin{axis} and \end{axis} to \begin{semilogaxis} and \end{semilogaxis} and I got environment undefined I tried loglogaxis which worked but gave awkward values for the y axis obviously so I would rather make it semilog
    – Sergio
    Commented Feb 15, 2021 at 16:00
  • Try semlogxaxis (in detail: semilogXaxis) and it should work. Also an advice for the future: read the pgfplot documentation and do not fear its many pages/examples, because they want to help you.
    – Venez
    Commented Feb 15, 2021 at 16:05

1 Answer 1

2

Here you go ...

\documentclass[tikz]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{semilogxaxis}[
title={Execution Time Using Varying Array Sizes },
xlabel={Array Length},
ylabel={Execution Time [milliseconds]},
xmin=0, xmax=1000000,
ymin=0, ymax=30,
xtick={0,1000,10000,100000,1000000},
ytick={0,5,10,15,20,25,30},
ymajorgrids=true,
grid style=dashed,
]
\addplot[color=blue,mark=square] coordinates {
    (1000,4.1)(10000,4.2)(100000,6.6)(1000000,26.0)
};
\end{semilogxaxis} % beware the two X letters in semilogxaxis
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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