1

The following codes are from the answers to this question and this question.

I would like to modify some individual parameters, but I could not do it:

  1. How to control some individual pin color and distance (the pin of node B* should be red) (the pin of node B should be longer)
  2. How to control some individual circle color (the circle of the node B* should be red)
  3. How to control some individual text box size (the box width at point 12,18 should have different width and color)

    \documentclass{beamer}
    \beamertemplatenavigationsymbolsempty
    \usepackage{verbatim}
    \usepackage{tikz}
    \usepackage{pgfplots}
    \usepackage{tkz-fct}
    \begin{document}
    \begin{frame}[fragile,t]
    \frametitle{ppf2cons}
    \tikzset{
    declare function={
    myslope(\x) = 24 - \x*(24/48);
    mycomplexfunction(\x) = sin(60*pow(\x,1.2)) + 6;
    },
    }
    \begin{tikzpicture}[
     dot/.style = {circle, black, scale=.8, fill, node contents={}},
     aligned pin/.style args={[#1]#2:#3}%
      {pin={[pin distance=4mm, pin edge={black, very thick, shorten >=-12pt},
        label={[append after command={%
          node[text width=18mm, color=black, fill=yellow!35, xshift=0cm, yshift=0cm, outer sep=0pt, inner sep=5pt,%
            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=64,
     xtick={0,12,24,27,48}, xticklabels={0,12,\llap{24},\rlap{27},48},
     ymin=0, ymax=30,
     ytick={12,13,18,24},  yticklabels={\raisebox{-12pt}{12},\raisebox{8pt}{13},18,24},
     tickwidth=.2cm,
     xlabel={P},
     xlabel style={xshift=.72cm, yshift=0cm}, xlabel style={right},
     ylabel={M},
     ylabel style={xshift=.2cm, yshift=.6cm}, ylabel style={above},
     xticklabel style={inner xsep=0cm, xshift=0cm, yshift=-.1cm}, 
     yticklabel style={inner ysep=0cm, xshift=-.1cm, yshift=0cm},
    samples=200,
    clip=false,
    ]
    \draw[ultra thick, blue] plot[samples at={0,12,24,48}, mark=*, mark options={black}] (axis cs:\x,{myslope(\x)});
    \addplot [ultra thick, mark=*] coordinates {(27,13)};
    \node at (axis cs:12,{myslope(12)}) [scale=.8, dot, aligned pin={[south west]65:bla bla bla bla bla bla}];
    \node at (axis cs:24,{myslope(24)}) [scale=.8, dot, aligned pin={[south west]45:bla bla bla bla bla bla}];
    \node at (axis cs:27,13) [scale=.8, dot, aligned pin={[west]-10:\textcolor {red}{bla bla bla bla bla bla}}];
    \draw [thick, black, densely dotted] (axis cs:0,{myslope(12)}) -- (axis cs:12,{myslope(12)}) node [black, xshift=.46cm, yshift=.05cm] {} -- (axis cs:12,0);
    \draw [thick, black, densely dotted] (axis cs:0,{myslope(24)}) -- (axis cs:24,{myslope(24)}) node [blue, xshift=-.34cm, yshift=-.3cm] {B} -- (axis cs:24,0);
    \draw [thick, red, densely dotted] (axis cs:0,13) -| node [red, xshift=.46cm, yshift=.1cm] {B*} (axis cs:27,0);
    \end{axis}
    \end{tikzpicture}
    \end{frame}
    \end{document}
    

enter image description here

Bobyandbob
  • 4,899
Hany
  • 4,709

1 Answers1

4

Instead of hardcoding values, you can define some new styles, and use those in aligned pin. Then you can locally modify those styles as you see fit.

For the black dot that should be red, because that is added as a separate \addplot, you just need to add red to the options there. (Note I removed the dot from the nodes, seems pointless to add dots like that when you already make those dots with the plots.)

There are some comments in the code, ask if anything is unclear.

enter image description here

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{ppf2cons}
\tikzset{
declare function={
myslope(\x) = 24 - \x*(24/48);
},
}
\begin{tikzpicture}[
 % removed dot, don't need it
 % make some new styles
 pinlabel/.style={text width=18mm, color=black, fill=yellow!35, xshift=0cm, yshift=0cm, outer sep=0pt, inner sep=5pt},
 pinstyle/.style={pin distance=4mm},
 % set default style of pin edges, instead of using pin edge={..}
 every pin edge/.style={black, very thick, shorten >=-12pt},
 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=64,
 xtick={0,12,24,27,48}, xticklabels={0,12,\llap{24},\rlap{27},48},
 ymin=0, ymax=30,
 ytick={12,13,18,24},  yticklabels={\raisebox{-12pt}{12},\raisebox{8pt}{13},18,24},
 tickwidth=.2cm,
 xlabel={P},
 xlabel style={xshift=.72cm, yshift=0cm}, xlabel style={right},
 ylabel={M},
 ylabel style={xshift=.2cm, yshift=.6cm}, ylabel style={above},
 xticklabel style={inner xsep=0cm, xshift=0cm, yshift=-.1cm}, 
 yticklabel style={inner ysep=0cm, xshift=-.1cm, yshift=0cm},
 % remove samples=200 and clip=false
]

% use \addplot
\addplot [ultra thick, blue, samples at={0,12,24,48}, mark=*, mark options={black}] {myslope(x)};

% add red here
\addplot [ultra thick, mark=*, red] coordinates {(27,13)};

% remove scale=0.8,dot from the following three nodes, add coordinate and {} at end
% use scoped (shorthand of scope environment) to locally modify the styles defined above
\scoped[pinlabel/.append style={text width=25mm,fill=blue!20}] 
  \node at (axis cs:12,{myslope(12)}) [coordinate, aligned pin={[south west]65:bla bla bla bla bla bla}] {};

\scoped[pinstyle/.append style={pin distance=3cm}]
  \node at (axis cs:24,{myslope(24)}) [coordinate, aligned pin={[south west]45:bla bla bla bla bla bla}] {};

\scoped[every pin edge/.append style={red}]
  \node at (axis cs:27,13) [coordinate, aligned pin={[west]-10:\textcolor {red}{bla bla bla bla bla bla}}] {};


\draw [thick, black, densely dotted] (axis cs:0,{myslope(12)}) -- (axis cs:12,{myslope(12)}) node [black, xshift=.46cm, yshift=.05cm] {} -- (axis cs:12,0);
\draw [thick, black, densely dotted] (axis cs:0,{myslope(24)}) -- (axis cs:24,{myslope(24)}) node [blue, xshift=-.34cm, yshift=-.3cm] {B} -- (axis cs:24,0);
\draw [thick, red, densely dotted] (axis cs:0,13) -| node [red, xshift=.46cm, yshift=.1cm] {B*} (axis cs:27,0);
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}

Addendum

If you want complete control over the look of each individual dot separately, you could just as well add the dot style back in, and then use \node [dot, aligned pin=.... Then you can just add options after dot to control those things, e.g. \node [dot, minimum size=30pt, blue, aligned pin=... to make a massive blue dot.

To change the size of the plotted markers, you use mark size, i.e. \addplot [..., mark size=10pt] .... Note that mark size sets the radius, while minimum size (for nodes) sets the diameter.

I modified dot slightly here.

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{ppf2cons}
\tikzset{
declare function={
myslope(\x) = 24 - \x*(24/48);
},
}
\begin{tikzpicture}[
 % changed size of dot
 dot/.style = {circle, black, inner sep=0,minimum size=6pt, fill, node contents={}},
 % make some new styles
 pinlabel/.style={text width=18mm, color=black, fill=yellow!35, xshift=0cm, yshift=0cm, outer sep=0pt, inner sep=5pt},
 pinstyle/.style={pin distance=4mm},
 % set default style of pin edges, instead of using pin edge={..}
 every pin edge/.style={black, very thick, shorten >=-12pt},
 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=64,
 xtick={0,12,24,27,48}, xticklabels={0,12,\llap{24},\rlap{27},48},
 ymin=0, ymax=30,
 ytick={12,13,18,24},  yticklabels={\raisebox{-12pt}{12},\raisebox{8pt}{13},18,24},
 tickwidth=.2cm,
 xlabel={P},
 xlabel style={xshift=.72cm, yshift=0cm}, xlabel style={right},
 ylabel={M},
 ylabel style={xshift=.2cm, yshift=.6cm}, ylabel style={above},
 xticklabel style={inner xsep=0cm, xshift=0cm, yshift=-.1cm}, 
 yticklabel style={inner ysep=0cm, xshift=-.1cm, yshift=0cm},
 % remove samples=200 and clip=false
]

% use \addplot! changed the samples at=
% mark size sets the radius of all the markers in this plot
\addplot [ultra thick, blue, samples at={0,48}, mark=*, mark size=10pt,mark options={black}] {myslope(x)};

% remove this
%\addplot [ultra thick, mark=*, red] coordinates {(27,13)};


% use scoped (shorthand of scope environment) to locally modify the styles defined above
\scoped[pinlabel/.append style={text width=25mm,fill=blue!20}] 
  % just as example: add minimum size=12pt to make this one larger minimum size sets the diameter
  \node at (axis cs:12,{myslope(12)}) [dot, minimum size=12pt, aligned pin={[south west]65:bla bla bla bla bla bla}];

\scoped[pinstyle/.append style={pin distance=3cm}]
  \node at (axis cs:24,{myslope(24)}) [dot, aligned pin={[south west]45:bla bla bla bla bla bla}];

\scoped[every pin edge/.append style={red}]
  % add red after dot
  \node at (axis cs:27,13) [dot, red, aligned pin={[west]-10:\textcolor {red}{bla bla bla bla bla bla}}];


\draw [thick, black, densely dotted] (axis cs:0,{myslope(12)}) -- (axis cs:12,{myslope(12)}) node [black, xshift=.46cm, yshift=.05cm] {} -- (axis cs:12,0);
\draw [thick, black, densely dotted] (axis cs:0,{myslope(24)}) -- (axis cs:24,{myslope(24)}) node [blue, xshift=-.34cm, yshift=-.3cm] {B} -- (axis cs:24,0);
\draw [thick, red, densely dotted] (axis cs:0,13) -| node [red, xshift=.46cm, yshift=.1cm] {B*} (axis cs:27,0);
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
Torbjørn T.
  • 206,688
  • I appreciate very much your effort. Just one more modification please. Since you removed dot/.style = {circle, black, scale=.8, fill}, how can individual circles size, color and fill be modified? – Hany Jul 13 '18 at 05:16
  • @Hany If you want control over each individual dot (and not just the B* that your question mentioned), then it's better to use dot the way you had it, and not add markers there in the plots, i.e. use samples at={0,48} in the first \addplot, and remove the second \addplot altogether. Then dot,red will give you a red dot, for example. – Torbjørn T. Jul 13 '18 at 06:33
  • So, you suggest that I use my original code and modify it, instead of using your code!! Is there a way to modify your code to control circle size (forget about color), it gives me more control! – Hany Jul 13 '18 at 07:29
  • 1
    @Hany I'm not entirely sure what you mean there, I was suggesting you take my code, and add dot back in, the way it was in your original code. My other modifications you can of course leave as it was, they are independent of the dot. I'll edit. – Torbjørn T. Jul 13 '18 at 07:33
  • 1
    @Hany Didn't see you edited the comment. If you want to change the size of the plotted markers, use mark size. Adding mark size=20pt for example to the \addplot options will make them rather large. – Torbjørn T. Jul 13 '18 at 07:42
  • Your new edited code is just what I wanted. I appreciate very much your efforts. – Hany Jul 13 '18 at 08:45