附录

附录

以下代码来自这个问题的答案问题和这个问题

我想修改一些单独的参数,但我无法做到:

  1. 如何控制个别引脚颜色和距离(节点B*的引脚应该是红色)(节点B的引脚应该更长)
  2. 如何控制某些单独的圆圈颜色(节点 B* 的圆圈应该是红色)
  3. 如何控制一些单独的文本框大小(点 12,18 处的框宽度应该具有不同的宽度和颜色)

    \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}
    

在此处输入图片描述

答案1

您可以定义一些新样式,并在 中使用它们,而不是对值进行硬编码aligned pin。然后,您可以根据需要在本地修改这些样式。

对于应该是红色的黑点,因为它是作为单独的添加的\addplot,您只需添加red到那里的选项即可。(请注意,我dot从节点中删除了,当您已经用图制作了这些点时,添加这样的点似乎毫无意义。)

代码里有一些注释,有什么不清楚的可以问。

在此处输入图片描述

\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}

附录

如果您想要完全控制每个点的外观,您也可以重新添加样式dot,然后使用\node [dot, aligned pin=...。然后,您只需添加选项即可dot控制这些内容,例如\node [dot, minimum size=30pt, blue, aligned pin=...制作一个巨大的蓝点。

要更改绘制标记的大小,请使用mark size,即\addplot [..., mark size=10pt] ...。请注意,mark size设置半径,而minimum size(对于节点)设置直径。

dot这里稍微修改了一下。

\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}

相关内容