How can the y-axis in a plot like the one below be relabeled from 0-max (here 0-3) to 0-1 in a flexible way that is independent of the concrete data? Is it e.g. possible to access the maximal y-value that occurred during the plot and use it to determine the position of the y-label 1?
This question continues the discussion on How do I plot a Cumulative Distribution Function (CDF) of Discrete Numbers in LaTex Environment?.
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\makeatletter
\long\def\ifnodedefined#1#2#3{%
\@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
\pgfplotsset{
discontinuous/.style={
scatter,
scatter/@pre marker code/.code={
\ifnodedefined{marker}{
\pgfpointdiff{\pgfpointanchor{marker}{center}}%
{\pgfpoint{0}{0}}%
\ifdim\pgf@y>0pt
\tikzset{options/.style={mark=*, fill=white}}
\draw [densely dashed,blue] (marker-|0,0) -- (0,0);
\draw plot [mark=*] coordinates {(marker-|0,0)};
\else
\tikzset{options/.style={mark=none}}
\fi
}{
\tikzset{options/.style={mark=none}}
}
\coordinate (marker) at (0,0);
\begin{scope}[options]
},
scatter/@post marker code/.code={\end{scope}}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[
clip=false,
jump mark left,
ymin=0,ymax=3.5,
xmin=14,xmax=35,
xlabel={income},
ylabel={cumulative distribution},
every axis plot/.style={very thick},
discontinuous,
table/create on use/cumulative distribution/.style={
create col/expr={\pgfmathaccuma + \thisrow{f(x)}}
}
]
\addplot [red] table [y=cumulative distribution]{
P(x) f(x)
14 0
15 1/5
18 2/5
25 3/5
31 4/5
33 1
35 0
};
\end{axis}
\end{tikzpicture}
\end{document}

