1

I have an y-axis with numbers from 0 to 200

I am trying to scale the y-axis in Tikz such that I get the same distance between points 0-20 and 20-200. (For instance: graph height is 8cm. I want the distance between points 0-20 and 20-200 to be equal in height.

I have tried to use y filter and logarithmic mode to make the graph better, but have not succeeded.

Axis options:


\ProvidesClass{master}[Redacted]

\NeedsTeXFormat{LaTeX2e}

\LoadClass[12pt]{report}

\setlength\parindent{0pt}

\RequirePackage[utf8]{inputenc}

\RequirePackage{
    graphicx, 
    minted, 
    color, 
    quoting, 
    tabularx, 
    fancyhdr, 
    listings, 
    ragged2e,
    glossaries, 
    hyperref, 
    pdfpages, 
    float,
    csquotes,
    subfiles,
    glossaries,
    hyperref
}

\RequirePackage[table, xcdraw]{xcolor}

\RequirePackage[pages=some]{background}

\RequirePackage[english]{babel}

\RequirePackage[nottoc]{tocbibind}

\RequirePackage[
    backend=biber,
    style=numeric,
    sorting=none,
    hyperref=true, 
    sortcites=true, 
    natbib=true, 
    style=ieee
]{biblatex}

\usepackage{pgfplotstable}
\usepackage{pgfplots}






\documentclass[../../main.tex]{subfiles}
\begin{document}
    \begin{figure}[!ht]
        \begin{center}
            \label{fig:results_default}
            \caption{Results of exact search queries with default settings.}
            \vspace{0.5cm}
            \begin{tikzpicture}
                %\pgfplotsset{
                %    y coord trafo/.code={
                %        \pgfmathparse{ #1<20 ? #1*10 : #1 }
                %    },
                %    y coord inv trafo/.code={
                %        \pgfmathparse{ #1<20 ? #1*10 : #1 }
                %    }
                %}

                \begin{axis}[
                    scale only axis,
                    grid=major,
                    height=15cm,
                    width=15cm,
                    %xmin=0, xmax=120,
                    %ymin=0, ymax=30,
                    %ystep=0.75,
                    %ymode=log,
                    %xmode=log,
                    %y filter/.code={\pgfmathparse{\pgfmathresult/150.}\pgfmathresult},
                    log ticks with fixed point,
                    %x filter/.code=\pgfmathparse{#1 + 6.90775527898214},
                    %y filter/.code=\pgfmathparse{#1<20 ? #1*9 : #1},
                    xlabel=Queried records in millions, 
                    ylabel=Query response time in seconds,
                    legend style={at={(0.05, 0.9)}, anchor=west}
                    ]

                    \addplot[color=blue, mark=triangle, thick] table [x=Records, y=MySQL]{./data/default_exact.dat};
                    \addlegendentry{$Exact_{MySQL}$}

                    \addplot[color=red, mark=triangle, thick] table [x=Records, y=MongoDB]{./data/default_exact.dat};
                    \addlegendentry{$Exact_{MongoDB}$}

                    \addplot[color=purple, mark=triangle, thick] table [x=Records, y=Elastic]{./data/default_exact.dat};
                    \addlegendentry{$Exact_{Elasticsearch}$}

                    \addplot[color=black, mark=triangle, thick] table [x=Records, y=Splunk]{./data/default_exact.dat};
                    \addlegendentry{$Exact_{Splunk}$}


                    \addplot[color=blue, mark=star, thick, dashed] table [x=Records, y=MySQL]{./data/default_wildcard.dat};
                    \addlegendentry{$Wildcard_{MySQL}$}

                    \addplot[color=red, mark=star, thick, dashed] table [x=Records, y=MongoDB]{./data/default_wildcard.dat};
                    \addlegendentry{$Wildcard_{MongoDB}$}

                    \addplot[color=purple, mark=star, thick, dashed] table [x=Records, y=Elastic]{./data/default_wildcard.dat};
                    \addlegendentry{$Wildcard_{Elasticsearch}$}

                    \addplot[color=black, mark=star, thick, dashed] table [x=Records, y=Splunk]{./data/default_wildcard.dat};
                    \addlegendentry{$Wildcard_{Splunk}$}

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

\end{document}

default_exact.dat:

Records MySQL   MongoDB Elastic Splunk
0       0       0       0       0
1       0.42    0.31    0       0.28
5       2.12    1.52    0       0.33
10      4.28    3.35    0       0.88
50      21.1    26.8    0       1.35
100     172.5   157     0.675   2.40

default_wildcard.dat:

Records MySQL   MongoDB Elastic Splunk
0       0       0       0       0
1       0.52    0.38    0       0.32
5       2.65    1.88    0       1.61
10      5.23    4.09    0       3.34
50      26.2    30.5    0       15.1
100     174.5   167     2.506   27.6

I want to make the line that is close to zero stand out. The current result looks like this: Graph

Is this possible in Tikz? If not, can I use any other methods such as log, for ymode to show the differences better? The goal is to visually distinguish the lines that are very close to each other.

  • 3
    Hi, welcome. See if tex.stackexchange.com/questions/359878/… helps. – Torbjørn T. May 3 at 20:01
  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code. – Andrew May 4 at 4:12
  • @TorbjørnT. Thank you for the suggestion. That seems to let me scale the y-axis, but the graphs did not align to the adjustment. Perhaps I did something wrong – Nicolai Prebensen May 4 at 13:03
  • @Andrew Thanks. I have edited the post and added the relevant code. – Nicolai Prebensen May 4 at 13:03
  • This is not exactly what'd I'd call a minimal working example: it doesn't compile and it's not minimal! :) – Andrew May 5 at 1:41
0

As Torbjørn suggests you can use y coord trafo and y coord inv trafo to do this. Motivated partly by pgfplots custom axis scaling function, you need to add the lines:

y coord trafo/.code={
  \pgfmathparse{#1<20.01 ? #1 : 20+(#1-20)/9}
  \pgfmathresult
},
y coord inv trafo/.code={
  \pgfmathparse{#1<20.01 ? #1 : (#1-20)*9+20}
  \pgfmathresult
},

to your code. The first of these rescales the y coordinates in the plot and the second applies the inverse map to print the correct labels on the axis. This results in:

enter image description here

Here is a full MWE. I have changed the size of the plot so that it displays better for me and removed your legend, since your wanted this to be "redacted", and added your data files to the MWE using filecontents:

\documentclass{report}
\usepackage{filecontents}

\begin{filecontents}{default_exact.dat}
Records MySQL   MongoDB Elastic Splunk
0       0       0       0       0
1       0.42    0.31    0       0.28
5       2.12    1.52    0       0.33
10      4.28    3.35    0       0.88
50      21.1    26.8    0       1.35
100     172.5   157     0.675   2.40
\end{filecontents}

\begin{filecontents}{default_wildcard.dat}
Records MySQL   MongoDB Elastic Splunk
0       0       0       0       0
1       0.52    0.38    0       0.32
5       2.65    1.88    0       1.61
10      5.23    4.09    0       3.34
50      26.2    30.5    0       15.1
100     174.5   167     2.506   27.6
\end{filecontents}

\usepackage{pgfplotstable}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
      %\pgfplotsset{
      %    y coord trafo/.code={
      %        \pgfmathparse{ #1<20 ? #1*10 : #1 }
      %    },
      %    y coord inv trafo/.code={
      %        \pgfmathparse{ #1<20 ? #1*10 : #1 }
      %    }
      %}

      \begin{axis}[
          scale only axis,
          grid=major,
          height=8cm,
          width=8cm,
          %xmin=0, xmax=120,
          %ymin=0, ymax=30,
          %ystep=0.75,
          %ymode=log,
          %xmode=log,
          %y filter/.code={\pgfmathparse{\pgfmathresult/150.}\pgfmathresult},
          log ticks with fixed point,
          %x filter/.code=\pgfmathparse{#1 + 6.90775527898214},
          %y filter/.code=\pgfmathparse{#1<20 ? #1*9 : #1},
          xlabel=Queried records in millions,
          ylabel=Query response time in seconds,
          legend style={at={(0.05, 0.9)}, anchor=west},
          % coordinate transformations applied to coordinates
          y coord trafo/.code={
            \pgfmathparse{#1<20.01 ? #1 : 20+(#1-20)/9}
            \pgfmathresult
          },
          y coord inv trafo/.code={
            \pgfmathparse{#1<20.01 ? #1 : (#1-20)*9+20}
            \pgfmathresult
          },
          ]

          \addplot[color=blue, mark=triangle, thick] table [x=Records, y=MySQL]{default_exact.dat};
          \addplot[color=purple, mark=triangle, thick] table [x=Records, y=Elastic]{default_exact.dat};

          \addplot[color=black, mark=triangle, thick] table [x=Records, y=Splunk]{default_exact.dat};

          \addplot[color=blue, mark=star, thick, dashed] table [x=Records, y=MySQL]{default_wildcard.dat};

          \addplot[color=red, mark=star, thick, dashed] table [x=Records, y=MongoDB]{default_wildcard.dat};

          \addplot[color=purple, mark=star, thick, dashed] table [x=Records, y=Elastic]{default_wildcard.dat};

          \addplot[color=black, mark=star, thick, dashed] table [x=Records, y=Splunk]{default_wildcard.dat};

      \end{axis}
  \end{tikzpicture}

\end{document}
  • Thank you very much. Your solution seems to be working as I wanted it to! – Nicolai Prebensen May 5 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.