I have shapes (some small graphics) defined with \newcommand. These are equipped with automatically printed y-coordinate (displayed as an "altitude"). I would like to put a series of such shapes on a graph. But I have troubles with correct positioning of them in the axis coordinate system. The other problem is that the settings of the first graphics are lost after second graphics is placed (it happens only within axis environment).
Code:
\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=newest}
\pgfkeys{
/seagull settings/.is family,
/seagull settings,
name/.estore in=\seagullname,
wingspan/.estore in=\seagullwingspan,
default/.style={%
name=Emma,
wingspan=3mm
}
}
\tikzset{
pics/seagull/.style args={xy #1:#2 span #3}{
foreground code={
\draw ($(#1,#2)-(#3,0mm)$) coordinate (-left wing)
.. controls +(1mm,1mm) and +(-1mm,1mm) .. +($1(#3,0mm)$) coordinate (-head)
.. controls +(1mm,1mm) and +(-1mm,1mm) .. +($2(#3,0mm)$) coordinate (-right wing);
}
}
}
\newcommand\bird[3][]{
\pgfkeys{/seagull settings,default,#1}
\path pic (\seagullname) {seagull=xy {#2}:{#3} span {\seagullwingspan}};
\node at ($(\seagullname-head)+(0mm,3mm)$) {altitude: #3};
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot
table[row sep=crcr]{%
40 8\
45 7\
50 6\
55 4\
60 4\
};
\bird[name=Emma]{55}{9} % <- beyond plot area (it has to be displayed)
\bird[name=Alexandra,wingspan=6mm]{50}{6}
\end{axis}
%\draw (Emma-head) -- +(0cm,-1cm); % <- gives an error
\end{tikzpicture}
\end{document}

%in the line with\draw (Emma-head) -- +(0cm,-1cm);, please. – forrest Jul 20 '20 at 04:10clip. You can setymax=10to extend "clip range" – ZhiyuanLck Jul 20 '20 at 04:24\newcommand. Here is explained, what I do: https://tex.stackexchange.com/questions/46422/axis-break-in-pgfplots. I ktow that the plot is clipped to be bounded by the plot frame. The extention of y-axis is not a solution - the range of coordinates has to be unchanged. Moreover, the macro generated with\newcommandhas to get the y-coordinete of its location and display it. Only for simplicity I used the symbol of a bird. What about the line%\draw (Emma-head) -- +(0cm,-1cm); % <- gives an error? – forrest Jul 20 '20 at 05:37axisenvironment is actually a wrappedtikzpictureenvironment, you can not access the named shape that are defined insideaxisfrom the outside. – ZhiyuanLck Jul 20 '20 at 07:14