I have a problem with the following tikz code (maybe, when reading this, skip at first the code and read the question which is at the end), that creates cobweb-diagrams:
\documentclass{article}
\usepackage{tikz, fullpage}
\usetikzlibrary{arrows}
\begin{document}
\thispagestyle{empty}
\begin{figure}[htbp]
\centering
\newcounter{j}
\pgfmathdeclarefunction{p}{1}{
\pgfmathparse{#1 > 0.5 ? 1 : ( #1 >0.25 ? 0.2 : 2* #1 )} %change
}
\begin{tikzpicture}[>=latex',scale=10]
\draw[color=blue,style=thick,domain=0:1] plot (\x,{p(\x)}); %change
\draw[color=green](0,0)--(1,1); %change
\draw[->](0,0)--(0,1) node[above]{$y$};
\draw[->](0,0)--(1,0) node[right]{$x$};
\newcounter{cnt}
\newcommand{\x}{.3} %change
\foreach \i in {1,...,4}{
\pgfmathparse{(p(\x)}
\let\y\pgfmathresult
\draw[color=magenta](\x,\x)--(\x,\y)--(\y,\y);
\draw[color=orange,dotted,line width=0.8pt]
(\x,\x)--(\x,0) node[below=8pt]{$u_\i$};
\pgfmathsetcounter{j}{\i+1}
\draw[color=blue,dotted,line width=0.8pt]
(\x,\y)--(0,\y) node[left=8pt] {$u_\thej$};
\global\let\x\y}
\end{tikzpicture}
\caption{description} %change
\end{figure}
\pgfmathdeclarefunction{p}{1}{
\pgfmathparse{(and(#1>0, #1<1))}
}
\end{document}
I asked a while ago this question, about how to create such diagrams and I got some very good answers out of which I accepted one which uses tikz to do that. Now the problem is: If I compile the code of the piecewise diagram, of the accepted answer it looks fine (just like the graphic of the corresponding code from the accepted answer). But if I change that code only slightly (I wrote %change to the lines, where I did changes; please notice that I know almost nothing about tikz, so I just changed that code at various places, observed what that did and thus shaped that code into the present one to suit my needs) the output looks broken/terrible:

The most sensible change I believe is the one, where I'm changing my piecewise function (since all the other changes involve only changing the domain of the plot, the number of iterations of the "cobwebs" and the point of the domain at which the iterations start) from
\pgfmathdeclarefunction{p}{1}{%
\pgfmathparse{#1>0.5 ? 1 : 2*#1 }%
}
to
\pgfmathdeclarefunction{p}{1}{
\pgfmathparse{#1 > 0.5 ? 1 : ( #1 >0.25 ? 0.2 : 2* #1 )}
}
since all the other changes of the original code from here worked with the original piecewise function.
The piecewise function I define still looks ok in the above plot (meaning the definition of the function corresponds to its plot), but the problem are the magenta iterates together with the orange and blue projections, which are somehow offset - and the plot itself isn't centered anymore. Please help me with the question: How can I make the iterates/the plot look ok again ?
(Interestingly, if I compile the document such that a *.ps one comes out instead a *.pdf one (I'm using texmaker -> the above output was compiled using "pdflatex" and then -"view pdf") the iterations aren't offest anymore and the plot is centered, but all the projections are suddenly very much offset to the right)
#1 > 0.5 ? 1 : ( #1 >0.25 ...2) more important when we draw the function, the graph seems to be outside the bounding box. Actually I don't have an answer to this problem :( I update my code in my other answer because I keep some useless code . – Alain Matthes Mar 24 '12 at 10:41