2

I have two points in a plane, both depending on several parameters. The coordinates of them shall fall within the range [0,1], i.e. within the red square:

enter image description here

I would like to draw these points for many values of the parameters, labelling them according to these values in order to show which of them fall within the red square and which not.

Here my code for the background and the red square.

\begin{tikzpicture}
\begin{axis}[xmin=-2,xmax=2,ymin=-2,ymax=2, samples=1000, xlabel={$c$},
ylabel={$s$},unbounded coords=discard]
\draw[red,thick,dashed] (0,0) -- (1,0) -- (1,1) -- (0,1) -- (0,0);
\end{axis}
\end{tikzpicture}
3

There undoubtedly are more elegant ways enter image description here

\documentclass{article}


\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{try.csv}
0.5  0.5
0.25 0.75
1.5 -1
-1 -1
\end{filecontents}

\begin{document}
\begin{tikzpicture}

\begin{axis}[xmin=-2,xmax=2,ymin=-2,ymax=2]
\draw[red,thick,dashed] (axis cs:0,0) rectangle (axis cs:1,1);
\begin{scope}
\addplot[only marks,blue,clip mode=individual] table {try.csv};
\end{scope}
\begin{scope}
\clip (axis cs:0,0) rectangle (axis cs:1,1);
\addplot[only marks,clip mode=individual,red] table {try.csv};
\end{scope}
\end{axis}
\end{tikzpicture}

\end{document}
  • Thank you! Is it possible to add a label? – Mark Mar 17 at 13:49
  • To each point or just one for the.blue points and one for the red? – JPi Mar 17 at 13:52
  • To each point, or by checking the points with different colours (green, blue, black, orange etc) – Mark Mar 17 at 15:37
  • 1
    @Mark I guess you should provide the data, i.e. the colors, first, then one can add the labels with nodes near coords. – user121799 Mar 17 at 18:42
  • I agree with @marmot – JPi Mar 17 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.