使用以下答案中的代码这个问题;
我想在 X/Y 轴上放置红色标记。我不知道该怎么做,所以我使用 \end{axis} 代码后绘制的节点手动绘制它们。如何使用放置绿色标记的代码来放置它们?
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\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!35, xshift=0cm, yshift=0cm, outer sep=0pt, inner sep=5pt, align=center},
pinstyle/.style={pin distance=10mm},
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},%
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,20}, xticklabels={0,10,20},
ymin=0, ymax=21,
ytick={10,20}, yticklabels={10,20},
tickwidth=.01cm,%
xlabel={},
xlabel style={xshift=.62cm, yshift=0cm}, xlabel style={right},
ylabel={},
ylabel style={xshift=0cm, yshift=.46cm}, ylabel style={above},
xticklabel style={inner xsep=0cm, xshift=0cm, yshift=-.16cm},
yticklabel style={inner ysep=0cm, xshift=-.16cm, 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, dash pattern=on .3cm off .2cm, samples at={0,20}, mark=*, mark options={blue, solid}, mark size=.168cm] {myslope(x)};
\addplot [samples at={10}, mark=*, mark options={green, solid}, mark size=.1cm] {myslope(x)};
\end{axis}
\node at (3.26,.14) [circle, draw, red, fill=red, scale=1.2]{};
\node at (.14,2.68) [circle, draw, red, fill=red, scale=1.2]{};
\end{tikzpicture}
\end{frame}
\end{document}
答案1
做就是了
\addplot [only marks,mark=*,red,mark size=5pt] coordinates {(0,10) (10,0)};
平均能量损失
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\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!35, xshift=0cm, yshift=0cm, outer sep=0pt, inner sep=5pt, align=center},
pinstyle/.style={pin distance=10mm},
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},%
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,20}, xticklabels={0,10,20},
ymin=0, ymax=21,
ytick={10,20}, yticklabels={10,20},
tickwidth=.01cm,%
xlabel={},
xlabel style={xshift=.62cm, yshift=0cm}, xlabel style={right},
ylabel={},
ylabel style={xshift=0cm, yshift=.46cm}, ylabel style={above},
xticklabel style={inner xsep=0cm, xshift=0cm, yshift=-.16cm},
yticklabel style={inner ysep=0cm, xshift=-.16cm, 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, dash pattern=on .3cm off .2cm, samples at={0,20}, mark=*, mark options={blue, solid}, mark size=.168cm] {myslope(x)};
\addplot [samples at={10}, mark=*, mark options={green, solid}, mark size=.1cm] {myslope(x)};
\addplot [only marks,mark=*,red,mark size=5pt] coordinates {(0,10) (10,0)};
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
附录:您始终可以通过在内部定义坐标axis
并在外部使用坐标来将坐标“走私”到外部。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[fragile,t]
\frametitle{}
\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!35, xshift=0cm, yshift=0cm, outer sep=0pt, inner sep=5pt, align=center},
pinstyle/.style={pin distance=10mm},
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},%
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,20}, xticklabels={0,10,20},
ymin=0, ymax=21,
ytick={10,20}, yticklabels={10,20},
tickwidth=.01cm,%
xlabel={},
xlabel style={xshift=.62cm, yshift=0cm}, xlabel style={right},
ylabel={},
ylabel style={xshift=0cm, yshift=.46cm}, ylabel style={above},
xticklabel style={inner xsep=0cm, xshift=0cm, yshift=-.16cm},
yticklabel style={inner ysep=0cm, xshift=-.16cm, 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, dash pattern=on .3cm off .2cm, samples at={0,20}, mark=*, mark options={blue, solid}, mark size=.168cm] {myslope(x)};
\addplot [samples at={10}, mark=*, mark options={green, solid}, mark size=.1cm] {myslope(x)};
\addplot [only marks,mark=*,red,mark size=5pt] coordinates {(0,10) (10,0)};
\coordinate (X) at (axis cs:0,10);
\end{axis}
\node[right=1pt of X,align=left,anchor=west,yshift=-height("\strut")]{This is above line \&\\ This is below line};
\end{tikzpicture}
\end{frame}
\end{document}