The following code is from the answer to this question. How to apply it to a draw plot line code from the answer to this question.

I mean I want to apply the code of (inserting text in a box inside a node applied to the green line), to the blue line drawn by (draw plot within the axis definition).

declare function={
%        myslope2(\x) = 24 - \x*(24/48);
    myslope(\x) = 8 - \x*(8/32);
    mycomplexfunction(\x) = sin(60*pow(\x,1.2)) + 6;
dot/.style = {circle, black, scale=.8, fill, node contents={}},
aligned pin/.style args={[#1]#2:#3}%
  {pin={[pin distance=10mm, pin edge={black, very thick, shorten >=-12pt},
    label={[append after command={%
      node[text width=35mm, color=black, fill=yellow!35, xshift=0cm, yshift=0cm, outer sep=0pt, inner sep=5pt,%
scale=.9, transform shape]
 axis lines=center, axis line style={black, thick,-latex},
 axis y line=left,axis x line=bottom,
 tick style={line width=.04cm, color=black, line cap=round},
 xmin=0, xmax=64,
 xtick={0,16,32}, xticklabels={0,16,32},
 ymin=0, ymax=16,
 ytick={4,8}, yticklabels={4,8},
 xlabel={P}, xlabel style={right},
 ylabel={M}, ylabel style={above},
 xticklabel style={inner xsep=0cm, xshift=0cm,yshift=-.1cm},
 yticklabel style={inner ysep=0cm,xshift=-.1cm,yshift=0cm},
\draw[ultra thick,blue] plot[samples at={0,16,32},mark=*,mark options={black}] (axis cs:\x,{myslope(\x)});
\draw[thick,black,densely dotted] (axis cs:0,{myslope(16)}) -- (axis cs:16,{myslope(16)}) node [black, xshift=.46cm, yshift=.05cm] {A} -- (axis cs:16,0);
\draw [thick,green] (0,2.84) -- node [dot, aligned pin={[south west]45:very very very very long long long  long text}] + (-40:4.44cm) node [pos=0, circle, draw, black, fill=black, scale=0.5]{} node [pos=1, circle, draw, black, fill=black, scale=0.5]{};

enter image description here

  • sorry, but i don't understand, what you like to obtain. add sinus wave to this picture? no one example has green line.
    – Zarko
    Jul 12 '18 at 8:25
  • The \draw [thick,green] (0,2.84) defines the green line with a text pinned to a node in it. I want to apply this text pinned to the node code to the blue line code (\draw[ultra thick, blue] plot) within the {axis}
    – Hany
    Jul 12 '18 at 9:26
  • and why this line is not in your mwe? please, make your mwe more complete.
    – Zarko
    Jul 12 '18 at 9:32
  • The lines codes are in my mwe. I tried ( \draw[ultra thick, blue] plot[samples at={0,16,32},mark=*,mark options={black}] (axis cs:\x,{myslope(\x)}) node [dot, aligned pin={[south west]45:very very very very long long long long text}]; ) but the text is pinned to the end of the line not to its center.
    – Hany
    Jul 12 '18 at 9:34
  • The green line is over the blue line, if you enlarge the view you can see them
    – Hany
    Jul 12 '18 at 9:59

I tried the following code \node at (axis cs:16,{myslope(16)}) [dot, aligned pin={[south west]45:very very very very long long long long text}]; and it works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.