I would like to create lists of ticks on the x and y axises. I noticed a method of generating a new list from this post [How to use a macro inside tick definition in pgfplots].
I modified that code into the following MWE. In my code, I wanted to create two lists of ticks based on the list {0.75,3.5,1.0,1.5,1.0,3.5,1.0,1.5}. The first list is simply to add up these values in sequence. The second list is to double the values of the first list. Then, the newly generated lists are used as the ticks of the axises.
\documentclass{article}
\usepackage{tikz}
%% Example code copied from another post.
\newcommand{\deflisttickold}[1]{
\gdef\listticksold{}% global list
\foreach \x[count=\xi] in {#1}{\global\let\maxitems\xi}% count the max number of items
\show \maxitems
\foreach \x[count=\xi] in {#1}{
\ifnum\xi=\maxitems
\xdef\listticksold{\listticks \x}
\else
\xdef\listticksold{\listticks \x,}
\fi
}
}
%% New code modified from \deflisttickold
\newcommand{\deflistticknewone}[1]{
\gdef\listticksnewone{}% global list
\pgfmathsetmacro{\currval}{0.0}
\foreach \x[count=\xi] in {#1}{\global\let\maxitems\xi}% count the max number of items
\foreach \x[count=\xi] in {#1}{
\pgfmathparse{\currval+\x}
\global\edef\currval{\pgfmathresult}
\ifnum\xi=\maxitems
\xdef\listticksnewone{\listticksnewone \currval}
\else
\xdef\listticksnewone{\listticksnewone \currval,}
\fi
}
}
\newcommand{\deflistticknewtwo}[1]{
\gdef\listticksnewtwo{}% global list
\pgfmathsetmacro{\lastval}{0.0}
\foreach \x[count=\xi] in {#1}{\global\let\maxitems\xi}% count the max number of items
\foreach \x[count=\xi] in {#1}{
\pgfmathparse{2.0*(\x-\lastval)}
\global\edef\lastval{\x}
\ifnum\xi=\maxitems
\xdef\listticksnewtwo{\listticksnewtwo \pgfmathresult}
\else
\xdef\listticksnewtwo{\listticksnewtwo \pgfmathresult,}
\fi
}
}
\edef\mylist{0.75,3.5,1.0,1.5,1.0,3.5,1.0,1.5}
\deflisttickold{\mylist}
\deflistticknewone{\mylist}
\deflistticknewtwo{\listticksnewone}
\begin{tikzpicture}
\begin{axis}[
xmode=linear,
ymode=linear,
axis x line*=bottom,
axis y line*=left,
tick label style={font=\small},
grid=both,
tick align=outside,
tickpos=left,
width=0.65\textwidth,
height=0.4\textwidth,
xmin=0,
xtick = \listticksnewone,
xticklabels = \listticksnewone,
ytick = \listticksnewtwo,
yticklabels = \listticksnewtwo,
]
\addplot coordinates {
(0.25, 2.5)
(1.5, 3)
(3.5, 3.5)
(5, 4.5)
(7, 5)
};
\end{axis}
\end{tikzpicture}
\end{document}
However, my code does not work well. If I use the given code for replicating a list, the newly generated list by \deflisttickold{\mylist} is truly a list. The lists generated by \deflistticknewone{\mylist} and \deflistticknewtwo{\listticksnewone} are incorrect.
Can anyone help me to figure out the problems? Thanks in advance.

