2

Using the following code from the answer of this question;

I would like to place red marks on X/Y axes. I could not figure out how, so I draw them manually using nodes drawn after \end{axis} code. How to put them using the code used for placing the green mark?

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

enter image description here

Hany
  • 4,709

1 Answers1

2

Just do

\addplot [only marks,mark=*,red,mark size=5pt] coordinates {(0,10) (10,0)};

MWE

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

enter image description here

ADDENDUM: You can always "smuggle" coordinates outside by defining them within the axis and using them outside.

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

enter image description here

  • Thank you very much. Just one more comment please, can a text box be added to the red marks – Hany Aug 20 '18 at 17:07
  • 1
    @Hany Of course it can, but then you need to use nodes, possibly nodes near coords. Could you please tell me what defines the content of those text boxes? –  Aug 20 '18 at 17:10
  • I would like to add this text just above the dashed line: \node [black, align=center] at (2.8,4.4) {This is above line &\[-1mm] This is below line}; – Hany Aug 20 '18 at 17:19
  • Thank you very much for your answer, comment and addition. – Hany Aug 21 '18 at 04:53