# Pgfplots: plot text along function

I want to illustrate a material model, especially the identical loading and unloading path, which are illustrated via arrows that follow the material model in the following picture.

I want to put labels on the arrows specifying loading and unloading. I managed to do that with the decorations library from this post, but I am not really happy with the result. Here are the issues:

• The Loading should not be located exactly on the arrow but rather have a little space between text and arrow.
• The decoration causes an arrow-tip at the beginning of the arrow I can't get rid of.
• I'd like to center the text along the array length, not use the left indent.
• Using the decorations-library the text looks kind of pixelated. Is there an alternative ?

Can anyone plz help me with any of the mentioned points?

\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\geometry{a4paper,left=25mm,right=25mm, top=25mm, bottom=25mm}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
domain=0:2,
xmin=0, xmax=2.25,
ymin=0, ymax=4.5,
samples=100,
axis y line=center,
axis x line=middle,
]
decoration={text along path,
text align={left indent={0.25\dimexpr\pgfdecoratedpathlength\relax}}
},
postaction={decorate},
][domain=0.5:1.5] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
\end{axis}
\end{tikzpicture}
\end{document}


Edit:

Thanks to @Harish Kumar I could solve the problems. Unfortunately, the decorations-library produces somewhat fuzzy text which looks like a pixel-graphics. Is there any way to circumvent this?

• Instead of using text align={left indent...} use text align={align=center}. I don't know how to fix the extra arrow head though :-) Apr 8, 2015 at 9:54
• If you wonder how to offset the text from the line, see this answer: tex.stackexchange.com/a/38708/32374 (not related directly to this question, but maybe a future question :-)) Apr 8, 2015 at 9:55
• For 1 and 3 use raise=1ex,text align={center}. For 2, I am looking at it.
– user11232
Apr 8, 2015 at 9:57

For increasing the gap between the line and text, you can use raise=<dimen>. To align text at the center, use text align=center. I could not find out why the extra arrow head comes (it is due to decorations, but why...). To bypass that extra head, you can plot two times, once with decoration and another with line like

\addplot[draw=none,
postaction={decorate,decoration={text along path,
text align={center}
}},
domain=0.5:1.5,
] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};     %%<--- decoration alone
domain=0.5:1.5,->,samples=150
] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};     %% line alone


Code:

\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\geometry{a4paper,left=25mm,right=25mm, top=25mm, bottom=25mm}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}

\pgfplotsset{compat=1.12}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
domain=0:2,
xmin=0, xmax=2.25,
ymin=0, ymax=4.5,
samples=100,
axis y line=center,
axis x line=middle,
]
postaction={decorate,decoration={text along path,
text align={center}
}},
domain=0.5:1.5,
] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
domain=0.5:1.5,->,,samples=150
] {2*0.7*(1+x)*(1-1/(1+x)^3)+0.5};
postaction={decorate,decoration={text along path,
text align={center},
}},
domain=0.5:1.5
] {2*0.7*(1+x)*(1-1/(1+x)^3)-0.5};
\end{axis}
\end{tikzpicture}
\end{document}


No fuzzy text for me

May be your system is using bitmap fonts.

• thanks @Harish Kumar . That was very helpful. How does it come, that the decoration text looks kind of like an unsharp pixel graphics? Is there an alternative? Apr 8, 2015 at 11:07
• I don't think so. I also get the fuzzy text in Adobe Acrobat and SumatraPDF Apr 8, 2015 at 11:28
• @krtek Oh! you meant fuzzy text. I don't get it with sumatra and adobe both. Your system is using bitmap fonts may be. Use \usepackage{lmodern} or \usepackage{cm-super}. See Why are Bitmap-Fonts used automatically?.
– user11232
Apr 8, 2015 at 13:17
• Alright. Works like a charm with \usepackage{charter} Apr 8, 2015 at 13:52