拍摄 3

拍摄 3

使用答案中的代码问题,生成了所附的顶部图表。是否可以修改代码,以便将红色节点 B* 绘制在绘制线之外,虚线从 x=27 延伸到 y=13;如所附的底部图表所示。此外,各个刻度标记 x=27 的标签是否可以向右移动,y=13 可以向上移动。

    \documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{1}
\tikzset{
declare function={
    myslope(\x) = 24 - \x*(24/48);
    mycomplexfunction(\x) = sin(60*pow(\x,1.2)) + 6;
},
}
\begin{tikzpicture}[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,24,27,48},
 ymin=0, ymax=30,
 ytick={12,13,18,24}, yticklabels={12,13,18,24},
 tickwidth=.2cm,
 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},
 samples=200,
 clip=false]
\draw[ultra thick,blue] plot[samples at={0,12,24,27,48},mark=*,mark options={black}] (axis cs:\x,{myslope(\x)});
\draw[thick,black,densely dotted] (axis cs:0,{myslope(12)}) -- (axis cs:12,{myslope(12)}) node [black, xshift=.46cm, yshift=.05cm] {A} -- (axis cs:12,0);
\draw[thick,green,densely dotted] (axis cs:0,{myslope(24)}) -- (axis cs:24,{myslope(24)}) node [green, xshift=.46cm, yshift=.05cm] {B} -- (axis cs:24,0);
\draw[thick,red,densely dotted] (axis cs:0,{myslope(27)}) -- (axis cs:27,{myslope(27)}) node [red, xshift=.46cm, yshift=.05cm] {B*} -- (axis cs:27,0);
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述 在此处输入图片描述

答案1

如果要将绿色虚线绘制到不同的 y 坐标,请使用不同的 y 坐标...即使用13而不是myslope(27)

当然,这不会移动点,所以我用了第二个\addplot来创建那个点。(我改为\draw ... plot,在环境\addplot中对我来说更有意义axis。)

对于刻度标签,您可以使用extra刻度。

在此处输入图片描述

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{pgfplots} % loads tikz
\begin{document}
\begin{frame}[fragile,t]
\frametitle{1}
\tikzset{
declare function={
    myslope(\x) = 24 - \x*(24/48);
    mycomplexfunction(\x) = sin(60*pow(\x,1.2)) + 6;
},
}
\begin{tikzpicture}[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},
 xmin=0, xmax=64,
 xtick={0,12,24,48}, 
 ymin=0, ymax=30,
 ytick={12,18,24}, 
 tickwidth=.2cm,
 xlabel={P}, xlabel style={above}, % changed right to above
 ylabel={M}, ylabel style={right}, % changed above to right
 xticklabel style={inner xsep=0cm, xshift=0cm,yshift=-.1cm},
 yticklabel style={inner ysep=0cm,xshift=-.1cm,yshift=0cm},
 % specify extra ticks and modifications to their style
 extra x ticks={27},
 extra y ticks={13},
 extra x tick style={xticklabel style={xshift=5pt}},
 extra y tick style={yticklabel style={yshift=5pt}}
]

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

\draw[thick,black,densely dotted] (axis cs:0,{myslope(12)}) -| node [above right] {A}(axis cs:12,0);
\draw[thick,green,densely dotted] (axis cs:0,{myslope(24)}) -| node [below left] {B}  (axis cs:24,0);
\draw[thick,red,densely dotted] (axis cs:0,13) -| node [above right] {B*} (axis cs:27,0);
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}

在上面的代码中,我删除了xticklabelsyticklabels,因为它们似乎没有必要。另一方面,当手动指定它们时,您可以使用它将其中一些稍微移动一下。例如xticklabels={0,12,\llap{24},\rlap{27},48},...,yticklabels={\raisebox{-10pt}{12},\raisebox{5pt}{13},18,24}

在此处输入图片描述

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{pgfplots} % loads tikz
\begin{document}
\begin{frame}[fragile,t]
\frametitle{1}
\tikzset{
declare function={
    myslope(\x) = 24 - \x*(24/48);
    mycomplexfunction(\x) = sin(60*pow(\x,1.2)) + 6;
},
}
\begin{tikzpicture}[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},
 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{-10pt}{12},\raisebox{5pt}{13},18,24}, 
 tickwidth=.2cm,
 xlabel={P}, xlabel style={above},
 ylabel={M}, ylabel style={right},
 xticklabel style={inner xsep=0cm, xshift=0cm,yshift=-.1cm},
 yticklabel style={inner ysep=0cm,xshift=-.1cm,yshift=0cm},
]

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

\draw[thick,black,densely dotted] (axis cs:0,{myslope(12)}) -| node [above right] {A}(axis cs:12,0);
\draw[thick,green,densely dotted] (axis cs:0,{myslope(24)}) -| node [below left] {B}  (axis cs:24,0);
\draw[thick,red,densely dotted] (axis cs:0,13) -| node [above right] {B*} (axis cs:27,0);
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}

拍摄 3

正如 Zarko 在一条(现已删除)评论中指出的那样,如果您有\pgfplotsset{compat=1.11}或更高版本号,那么中的 等axis cs:是默认的,因此不必明确指定。我还删除了/样式,而是手动使用和设置/的位置。我想使用您喜欢的任何方法。另一个小问题,我使用( )代替了原始代码中更麻烦的( ) 。\drawaxisaxis x lineaxis y lineaxis lines=leftxlabelylabelticklabel shiftxyticklabel styleyxshift

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{pgfplots} % loads tikz
\pgfplotsset{compat=1.11} % among other things, makes axis cs: default
\begin{document}
\begin{frame}[fragile,t]
\frametitle{1}
\tikzset{
declare function={
    myslope(\x) = 24 - \x*(24/48);
}
}
\begin{tikzpicture}[scale=.9, transform shape]
\begin{axis}[
 axis lines=left, % instead of center, removed the othe axis x/y line options
 axis line style={black, thick,-latex},
 tick style={line width=.04cm, color=black, line cap=round},
 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{-10pt}{12},\raisebox{5pt}{13},18,24}, 
 tickwidth=.2cm,
 xlabel={P},
 ylabel={M},
 every axis x label/.style={at={(1,0)},above}, % manually position xlabel
 every axis y label/.style={at={(0,1)},right}, % manually position ylabel
 ticklabel shift=2pt % move all ticklabels away from axis
]

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

\draw[thick,black,densely dotted] (0,{myslope(12)}) -| node [above right] {A}  (12,0);
\draw[thick,green,densely dotted] (0,{myslope(24)}) -| node [below left]  {B}  (24,0);
\draw[thick,red,densely dotted]   (0,13)            -| node [above right] {B*} (27,0);
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}

答案2

我从未使用过 beamer 类,因此我在文章模式下尝试了它。

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfkeys}
\begin{document}
        \begin{tikzpicture}[scale=0.2]
            \draw[thick, blue] (0,24) -- (48,0);
            \draw[very thick,->,>=latex] (0,0) -- (55,0);
            \draw[very thick,->,>=latex] (0,0) -- (0,30);
            \filldraw[thick,densely dotted] (0,18) -- (12,18) node[above right]{$A$} circle (0.35)-- (12,0);
            \filldraw[thick,densely dotted,red](0,13) -- (27,13)node[above right]{$B*$} circle (0.35) -- (27,0);
            \filldraw[thick,densely dotted](0,12) -- (24,12)node[above right]{$B$} circle (0.35) -- (24,0);
        \end{tikzpicture}
\end{document}

如果我理解正确的话,它似乎提供了您想要的东西。您可以轻松地在轴上添加刻度。

相关内容