0

I would like to manually adjust the distance between the x ticks in my plot. I am changing the value in xtick distance without any visible effect. Since my labels are quite large, I would like to spread the x axis on most of the page width, something like 0.75\textwidth.

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
\begin{axis}[axis y line=middle,
    axis x line=bottom,
    x axis line style={dashed},
    xlabel={Time steps},
    ylabel={State and input variables},
    xtick distance=30,
    xtick={-4,-2,0,2,4,6},
    xticklabels={$k-2$,$k-1$,$k$,$k+1$,$k+2$,$k+3$},
    ytick={},
    yticklabels={},
    xmin=-8,
    xmax=8,
    ymin=0,
    ymax=1.1]
\addplot[const plot,no marks] coordinates {(0,0) (1,0.25) (2,0.4) (3,0.5) (4,1) (4.49,1)};
\addplot[draw=blue,const plot,no marks] coordinates {(-4,0.15) (-2,0.05) (0,0.2) (2,0.45) (4,0.7) (6,1)};
\addplot[const plot,dashed,no marks] coordinates {(-8,1) (8,1)};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

Any ideas ?

Thanks in advance

RockyRock
  • 1,221
  • xtick distance doesn't have any effect when you also state xtick. Also it is strange that for every DeltaX of 2 you only increase the corresponding labels by +1. Is that intended? – Stefan Pinnow Sep 17 '18 at 10:00
  • 1
    It was a poor attempt at spacing the x ticks... I have found a command that works x=7.5mm that scales the x axis. – RockyRock Sep 17 '18 at 10:05
  • Do you want to delete your question, close it as duplicate or as "solved in the comments"? – Stefan Pinnow Sep 17 '18 at 10:06

0 Answers0