0

here

How can I draw above picture by using tikz or pgf?

  • You probably want pgfplots. – Davislor Dec 25 '19 at 11:14
  • 2
    @Davislor pgfplots big hammer for a little fly – Alain Matthes Dec 25 '19 at 11:19
  • The problem seems to be Texstudio. The question is unclear ! – Alain Matthes Dec 25 '19 at 11:21
5

tkz-euclide was created to make these kind of diagrams here 2.50 beta. CTAN version will be ready soon.

\documentclass[border=.25cm]{standalone}
\usepackage{tkz-euclide}

\begin{document}
\begin{tikzpicture}
\tkzInit[xmax=4,ymax=4]
\tkzDefPoints{0/1/A_1,1/0/A_2,2/3/B_1,3/3/B_2}
\tkzGrid
\tkzDrawXY[label={}]\tkzLabelXY
\tkzDrawPoints[blue](A_1,A_2,B_1,B_2)
\tkzLabelPoints[blue,above right](A_1,A_2,B_1,B_2)
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
5

1. Why not using (a table-plot from) pgfplots?

This is usually easier (and developable) instead of placing everything that is to be shown as a node in plain-TikZ.

enter image description here

\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
x=1.5cm, y=1.5cm,
xtick={0,1,...,3},
ytick={1,...,3},
axis y line=middle, % new
axis x line=bottom,% new
axis line style = {-},
grid=major,
enlarge x limits={abs=0.4,upper},
enlarge y limits={abs=0.4,upper},
]
\addplot[blue, mark=*,only marks,
visualization depends on={value \thisrow{Name}\as\name},
nodes near coords = {$\name$},
nodes near coords align={south west},
] table[x=X,y=Y] {
X   Y   Name
0   1   A_1
1   0   A_2
2   3   B_1
3   3   B_2
};
\end{axis}
\end{tikzpicture}
\end{document}

2. Only TikZ.

enter image description here

\documentclass[border=5pt, tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% CoSy
\draw[help lines] (-0.4,-0.4)grid(3.75,3.75);
\draw[] (-0.5,0)-- (3.75,0);
\draw[] (0,-0.5)-- (0,3.75);
\node[left=4pt, below]{0};  
\foreach \x in{1,...,3} 
\draw[xshift=\x cm] (0,2pt) -- (0,-2pt) node[below,fill=white]{\x};

\foreach \y in{1,...,3} 
\draw[yshift=\y cm] (2pt,0) -- (-2pt,0) node[left,fill=white]{\y};

% Points
\foreach \x/\y/\Name in {0/1/A_1, 1/0/A_2, 2/3/B_1, 3/3/B_2}
\node[circle, fill=blue,inner sep=2pt, 
label={[anchor=-135, text=blue]:$\Name$}
]at (\x,\y){};
\end{tikzpicture}
\end{document}
| improve this answer | |
  • Good answer, but the 0 at origin is missed. – Ice0cean Dec 25 '19 at 12:52
  • Oh my dear! :) I will add that 0; gimme a couple of minutes. – cis Dec 25 '19 at 12:53
2

Definitely not ideal but maybe a pace to start from:

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-0.4,-0.4)grid(3.75,3.75);
\draw(-0.5,0)-- (3.75,0);
\draw(0,-0.5)-- (0,3.75);
\node[fill=white] at (-0.4,-0.4){0};
\node[fill=white] at (-0.4,1){1};
\node[fill=white] at (-0.4,2){2};
\node[fill=white] at (-0.4,3){3};
\node[fill=white] at (1,-0.4){1};
\node[fill=white] at (2,-0.4){2};
\node[fill=white] at (3,-0.4){3};
\node[circle, fill=blue,inner sep=2pt,label=45:\color{blue}$A_1$]at (0,1){};
\node[circle, fill=blue,inner sep=2pt,label=45:\color{blue}$A_2$]at (1,0){};
\node[circle, fill=blue,inner sep=2pt,label=45:\color{blue}$B_1$]at (2,3){};
\node[circle, fill=blue,inner sep=2pt,label=45:\color{blue}$B_2$]at (3,3){};
\end{tikzpicture}
\end{document}

Shortened version:

\documentclass{article}
\usepackage{tikz}

\newcommand{\labelledpoint}[2]{\node[circle, fill=blue,inner sep=2pt,label=45:\color{blue}$#2$]at (#1){};}

\begin{document}

\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (-0.4,-0.4)grid(3.75,3.75);
\draw(-0.5,0)-- (3.75,0);
\draw(0,-0.5)-- (0,3.75);
\node[fill=white] at (-0.4,-0.4){0};
\foreach \x in {1,2,3} \node[fill=white] at (-0.4,\x){\x};
\foreach \x in {1,2,3} \node[fill=white] at (\x,-0.4){\x};
\labelledpoint{0,1}{A_1}
\labelledpoint{1,0}{A_2}
\labelledpoint{2,3}{B_1}
\labelledpoint{3,3}{B_2}
\end{tikzpicture}

\end{document}
| improve this answer | |
  • 1
    If you want to use plain-TikZ, you can make it "ideal" by using foreach-loops, because the same stuff is used several times. ;) – cis Dec 25 '19 at 12:52
  • @cis: Thank your for your suggestion. Unfortunately I don't have lot of experience in using loops in tikz, so the shortened version I added to my answer is everything I could come up with. – leandriis Dec 25 '19 at 13:36
  • I added a plain-TikZ-answer on my pgfplots-answer, with that what I thought about. But your way is ok too. – cis Dec 25 '19 at 13:38
2

A pstricks solution:

\documentclass[border=6pt, svgnames]{standalone}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{mathastext}
\usepackage{pst-eucl, pst-plot}

\begin{document}

\psset{psgrid, gridcolor=Gainsboro!60, gridwidth=0.6pt, subgriddiv=1, gridlabels=0pt}
\begin{pspicture*}[](-0.6,-0.6)(3.8,3.8)
\psgrid(0,0)(-0.6,-0.6)(3.8,3.8)
\psaxes[showorigin=false, labelsep =0pt, ticks=none](0,0)(-0.6,-0.6)(3.8,3.8)
\uput{6pt}[dl](0,0){$0$}
\psset{linecolor=SteelBlue}\color{SteelBlue!80}
\pstGeonode[PosAngle=45](0,1){A_1}(1,0){A_2}(2,3){B_1}(3,3){B_2}
\end{pspicture*}

\end{document}

enter image description here

| improve this answer | |

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.