0

I have written this latex code that generates a plotting of lines. How can i make the sides have every value instead of only the even values ? Thank you.

Code:

 \documentclass{article}
    \usepackage{tikz}
    \usepackage{pgfplots}

\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
        \begin{axis}[
            name = plot,
            xlabel=Input File,
            ylabel=Execution Time]
        \addplot[color=red, mark=*] coordinates {
            (1,0)
            (2,1)
            (3,2)
            (4,3)
            (5,4)
            (6,5)
            (7,6)
            (8,7)
            (9,8)
            (10,10)
        };\label{C}
        \addplot[color=blue, mark=*] coordinates {
            (1,1)
            (2,-1)
            (3,5)
            (4,5)
            (5,6)
            (6,3)
            (7,4)
            (8,2)
            (9,10)
            (10,4)
        };\label{Py}
        \end{axis}
        \node[anchor=north,fill=white,draw=black] (legend) at ($(plot.north)-(0 mm, 1 mm)$) {\begin{tabular}{l l}
            C & \ref{C} \\
            Py & \ref{Py}
        \end{tabular} };
\end{tikzpicture}
\end{document}

i want the values in red to go from the 1st to the last in the coordinates, not just even values

1
  • Add options xtick distance=1, ytick distance=1 to axis environment. Commented May 11, 2020 at 14:04

2 Answers 2

1

The spacing of xtick and ytick can be controlled by xtick distance and ytick distance. In your case, set both to be 1:

\begin{axis}[
name = plot,
xtick distance=1,
ytick distance=1,
xlabel=Input File,
ylabel=Execution Time]
1

For the interval between ticks, you can use xtick distance=1 and ytick distance=1. I added xmin=0 and hide obscured x ticks=false to show the x tick at abscissa 0, plus a more idiomatic way to compose the legend with the appearance you want.

The legend code uses:

  • in the options of the axis environment: legend style={at={([yshift=-1mm]0.5,1)}, anchor=north} for legend placement and legend plot pos=right to swap the marker and label between left and right positions;

  • after the respective \addplot commands, \addlegendentry{C} and \addlegendentry{Py}.

\documentclass[tikz, border=1mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}       % for instance, but 1.16 works as well

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
      xlabel=Input file,
      ylabel=Execution time,
      xtick distance=1,
      ytick distance=1,
      xmin=0,                      % Added to make the
      hide obscured x ticks=false, % xtick at 0 visible.
      legend style={at={([yshift=-1mm]0.5,1)}, anchor=north},
      legend plot pos=right,
      ]
  \addplot[color=red, mark=*] coordinates {
      (1,0)
      (2,1)
      (3,2)
      (4,3)
      (5,4)
      (6,5)
      (7,6)
      (8,7)
      (9,8)
      (10,10)
  };
  \addlegendentry{C}
  \addplot[color=blue, mark=*] coordinates {
      (1,1)
      (2,-1)
      (3,5)
      (4,5)
      (5,6)
      (6,3)
      (7,4)
      (8,2)
      (9,10)
      (10,4)
  };
  \addlegendentry{Py}
  \end{axis}
\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 .