6

For the MWE below:

\documentclass{report}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}


\begin{document}

\begin{figure}[H]
\begin{tikzpicture}
\begin{axis}[%
scaled y ticks = true,
width=1*\textwidth,
height=8cm,
xlabel={Query $\#$},
ylabel={Elapsed Time (in seconds)},
grid=both,
minor x tick num=5,
minor y tick num=5,
enlarge x limits=0,
legend entries={Original, byHalf, Random, Hybrid},
scaled x ticks = true
]
\addplot [
color=blue,mark=x,
solid,
line width=1.0pt
]
coordinates{
(0,39.0819) (1,2292) (2,4484.82) (3,6057.37) (4,38.3475) (5,15.4616) (6,38.5286) (7,15.411) (8,38.3627) (9,14.8773) (10,15.4079) (11,38.8762) (12,20.9027) (13,35.6657) 
};

\addplot [
color=red,mark=x,
solid,
line width=1.0pt
]
coordinates{
(0,38.9575) (1,2720.19) (2,1929.3) (3,1677.22) (4,111.165) (5,68.6833) (6,94.4457) (7,76.0591) (8,94.0201) (9,109.844) (10,78.6465) (11,91.7805) (12,12.9179) (13,78.6684) 
};


\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

If you compile it, you will see that the last part of the plot looks as if the lines are touching each other and they look like they are the same but actually there is about 50 seconds between them. This happens since the y-axis ticks advance (automatically) with steps of 1000.

How can I control this ? Is it possible to first make it go with steps of 100 then when it reaches 1000, switch to steps of 1000 ?

3
  • do you mean something like ytick={100,200,...,1000,2000,3000,...,6000},?
    – cmhughes
    Aug 31, 2012 at 17:49
  • yes. Is that what should I add to achieve this ?
    – Cemre
    Aug 31, 2012 at 17:53
  • it's one way; I think the answer you've received is far better though, and is (imho) the way to go :)
    – cmhughes
    Aug 31, 2012 at 19:21

1 Answer 1

9

The axis you currently use are linear. This means, if you add more points between 0 and 1000, you add just more lines and labels in the same distance (the distance between 0 and 1000 will still be the same).

To highlight the differences between 0 and 1000 you can use a logarithmic scale. Using a logarithmic scale, the distance between 0 and 10 will be the same as the distance between 10 and 100 or 100 and 1000 (and so on).

Your example will look like this with a logarithmic y-axis:

screenshot

\documentclass{report}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}


\begin{document}

\begin{figure}[H]
  \begin{tikzpicture}
    \begin{semilogyaxis}[%
      width=1*\textwidth,
      height=8cm,
      xlabel={Query $\#$},
      ylabel={Elapsed Time (in seconds)},
      grid=both,
      enlarge x limits=0,
      legend entries={Original, byHalf, Random, Hybrid},
      scaled x ticks = true
    ]
    \addplot [color=blue,mark=x,solid,line width=1.0pt]
      coordinates{
        (0,39.0819) (1,2292) (2,4484.82) (3,6057.37) (4,38.3475) (5,15.4616) (6,38.5286) (7,15.411) (8,38.3627) (9,14.8773) (10,15.4079) (11,38.8762) (12,20.9027) (13,35.6657) 
   };

    \addplot [color=red,mark=x,solid,line width=1.0pt]
      coordinates{
       (0,38.9575) (1,2720.19) (2,1929.3) (3,1677.22) (4,111.165) (5,68.6833) (6,94.4457) (7,76.0591) (8,94.0201) (9,109.844) (10,78.6465) (11,91.7805) (12,12.9179) (13,78.6684) 
    };
  \end{semilogyaxis}
\end{tikzpicture}
\end{figure}

\end{document}

Instead of using

\begin{semilogyaxis} 
...
\end{semilogyaxis}

you can also use

\begin{axis}[xmode=normal,ymode=log]
...
\end{axis}

For more settings and infos have a look at the pgfplots documentation (page 16-19).

1
  • This is not exactly answering the OP question, but it is the way to go. +1. Aug 31, 2012 at 18:49

You must log in to answer this question.

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