2

Using the following code from the answer of this question

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{1}
\tikzset{%
declare function={
myslope(\x) = 20 - \x*(20/20);
},
}
\begin{tikzpicture}[
 dot/.style = {circle, black, inner sep=0, minimum size=6pt, fill, node contents={}},
 pinlabel/.style={text width=35mm, color=black, fill=yellow!20, xshift=0cm, yshift=0cm, outer sep=0pt, inner sep=5pt},
 pinstyle/.style={pin distance=10mm},
 every pin edge/.style={black, very thick, shorten >=-20pt},
 aligned pin/.style args={[#1]#2:#3}%
  {pin={[pinstyle,
  label={[append after command={%
  node[pinlabel,%
    at=(\tikzlastnode.#2),
    anchor=#1,
          ]{#3}}]center:{}}
        ]#2:{}}%
  },
scale=.9, transform shape]
\begin{axis}[
 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},%
 font=\normalsize, color=black,%
 xmin=0, xmax=21,
 xtick={0,10}, xticklabels={0,10},
 ymin=0, ymax=21,
 ytick={10}, yticklabels={10},
 tickwidth=.01cm,%
 xlabel={$A$},
 xlabel style={xshift=.62cm, yshift=0cm}, xlabel style={right},
 ylabel={$O$},
 ylabel style={xshift=0cm, yshift=.46cm}, ylabel style={above},
 xticklabel style={inner xsep=0cm, xshift=0cm, yshift=-.1cm},
 yticklabel style={inner ysep=0cm, xshift=-.1cm, yshift=0cm},
]
\draw [thick, black, densely dashed] (axis cs:0,{myslope(10)}) -- (axis cs:10,{myslope(10)}) node [black, xshift=.46cm, yshift=.05cm] {$$} -- (axis cs:10,0);

\addplot [ultra thick, blue, dashed, samples at={10}, mark=*, mark options={blue, solid}, mark size=.12cm] {myslope(x)};

\addplot [ultra thick, blue, dashed, samples at={0,10,20}, mark=*, mark options={blue, solid}, mark size=.12cm,-latex] {myslope(x)};

\scoped[pinlabel/.append style={text width=20mm}, pinstyle/.append style={pin distance=8mm}] 
 \node at (axis cs:10,{myslope(10)}) [dot, aligned pin={[north west, xshift=.2cm, yshift=.4cm]65:bla bla bla bla}] {};
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}

which gives me

this drawing

How to make the following modifications to look like

this drawing

  1. make the mark on position 10,10 in a different size and colour.
  2. draw a frame around the text.
  3. make the pin displayed with an angle.
Hany
  • 4,709

1 Answers1

3

I haven't used pins often and instead I would \node and connect it with a \draw.

To change the color of the marker at position (10,10) adjust the mark color in samples at={10}. You were also overwriting this with the subsequent samples at={0,10,20} (which I corrected to be samples at={0,20})

To add the frame around the text specify a draw=<color> option to the \node.

The (X.170) is an attempt to start the line from the bla box at the approximate position indicated in your figure. I personally would just use (X.west) instead. If you don't want to start at the node your can instead use ([xshift=-5pt]X.170) to shift the start point to the left by 5pt.

enter image description here

Code:

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{1}
\tikzset{%
declare function={
myslope(\x) = 20 - \x*(20/20);
},
}
\begin{tikzpicture}[
 dot/.style = {circle, black, inner sep=0, minimum size=6pt, fill, node contents={}},
 pinlabel/.style={text width=35mm, color=black, fill=yellow!20, xshift=0cm, yshift=0cm, outer sep=0pt, inner sep=5pt},
 pinstyle/.style={pin distance=10mm},
 every pin edge/.style={black, very thick, shorten >=-20pt},
 aligned pin/.style args={[#1]#2:#3}%
  {pin={[pinstyle,
  label={[append after command={%
  node[pinlabel,%
    at=(\tikzlastnode.#2),
    anchor=#1,
          ]{#3}}]center:{}}
        ]#2:{}}%
  },
scale=.9, transform shape]
\begin{axis}[
 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},%
 font=\normalsize, color=black,%
 xmin=0, xmax=21,
 xtick={0,10}, xticklabels={0,10},
 ymin=0, ymax=21,
 ytick={10}, yticklabels={10},
 tickwidth=.01cm,%
 xlabel={$A$},
 xlabel style={xshift=.62cm, yshift=0cm}, xlabel style={right},
 ylabel={$O$},
 ylabel style={xshift=0cm, yshift=.46cm}, ylabel style={above},
 xticklabel style={inner xsep=0cm, xshift=0cm, yshift=-.1cm},
 yticklabel style={inner ysep=0cm, xshift=-.1cm, yshift=0cm},
]
\draw [thick, black, densely dashed] (axis cs:0,{myslope(10)}) -- (axis cs:10,{myslope(10)}) node [black, xshift=.46cm, yshift=.05cm] {$$} -- (axis cs:10,0);

\addplot [ultra thick, blue, dashed, samples at={10}, mark=*, mark options={orange, solid}, mark size=.12cm] {myslope(x)};

\addplot [ultra thick, blue, dashed, samples at={0,20}, mark=*, mark options={blue, solid}, mark size=.12cm,-latex] {myslope(x)};

%\scoped[pinlabel/.append style={text width=20mm}, pinstyle/.append style={pin distance=8mm}] % \node at (axis cs:10,{myslope(10)}) [dot, aligned pin={[north west, xshift=.2cm, yshift=.4cm, draw=red]35:bla bla bla bla}] {};

\node [text width=20mm, draw=red, fill=yellow!20] (X) at ([shift={(35:2.5cm)}]axis cs:10,{myslope(10)}) {bla bla bla bla};

\draw (X.170) -- ++(-0.5cm,0) -- (axis cs:10,{myslope(10)}); \end{axis} \end{tikzpicture} \end{frame} \end{document}

Peter Grill
  • 223,288
  • Thank you very much. Just in case I want to use your very fine modification to the pin option, how can this be done – Hany Aug 02 '18 at 07:38
  • 1
    @Hany: I didn't use the pin option, and instead created a \node and manually did the \draw from the \node to the desired point. – Peter Grill Aug 02 '18 at 08:25