# How to create this image (graphing)

I want to create a graph with only the first quadrant. The values of x can only go from 0 to 9 and the values of y can only go from 0 to 9. In this graph, I want dots for (2,5), (3,3), (5,2) and (7,1). Above each pair specified I want dots above it. For example, the dots above (2,5) are (2,6), (2,7), (2,8) and (2,9). Does anyone know how to do this?

-
Welcome to LaTeX! Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. If you don't have the relevant LaTeX skills a screenshot and a very basic document starting from \documentclass{... and ending with \end{document} is also sufficient. –  percusse Nov 10 '12 at 21:14
As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again until you get more rep points. –  percusse Nov 10 '12 at 21:15
I'm sorry I don't understand what you mean by "include the image as normal and remove the !" –  Middle School Teacher Nov 10 '12 at 21:26
If you use the image inclusion button above the question (in the question edit window) it will place a link automatically with a ! prefixed. If you remove that it becomes a normal link and we can add it for you until you get enough reputation points. –  percusse Nov 10 '12 at 21:29
Is that the picture you intended to upload? –  Peter Grill Nov 10 '12 at 21:39

By tikz -- brute force:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[very thin, color=gray] (0,0) grid (10,10);
\draw [very thick, -stealth] (0,0) -- (11,0);
\draw [very thick, -stealth] (0,0) -- (0,11);
\foreach \x in {0,1,...,10}{
\draw [thick] (\x,0) -- (\x,-0.2) node [below] {\x};
}
\foreach \y in {0,1,...,10}{
\draw [thick] (0,\y) -- (-0.2,\y) node [left] {\y};
}
\foreach \x/\y in {2/5,2/6,2/7,2/8,2/9}{
\draw [fill=black] (\x,\y) circle (2pt);
}
\foreach \x/\y in {3/3,3/4,3/5,3/6,3/7,3/8,3/9}{
\draw [fill=black] (\x,\y) circle (2pt);
}
\foreach \x/\y in {5/2,5/3,5/3,5/4,5/5,5/6,5/7,5/8,5/9}{
\draw [fill=black] (\x,\y) circle (2pt);
}
\foreach \x/\y in {7/1,7/2,7/3,7/4,7/5,7/6,7/7,7/8,7/9}{
\draw [fill=black] (\x,\y) circle (2pt);
}
\end{tikzpicture}
\end{document}


Using plot function of tikz:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[very thin, color=gray] (0,0) grid (10,10);
\draw [very thick, -stealth] (0,0) -- (11,0);
\draw [very thick, -stealth] (0,0) -- (0,11);
\foreach \x in {0,1,...,10}{
\draw [thick] (\x,0) -- (\x,-0.2) node [below] {\x};
}
\foreach \y in {0,1,...,10}{
\draw [thick] (0,\y) -- (-0.2,\y) node [left] {\y};
}
\draw plot [only marks,mark=*] coordinates {(2,5) (2,6) (2,7) (2,8) (2,9)
(3,3) (3,4) (3,5) (3,6) (3,7) (3,8) (3,9)
(5,2) (5,3) (5,4) (5,5)(5,6) (5,7) (5,8) (5,9)
(7,1)(7,2)(7,3)(7,4)(7,5)(7,6)(7,7)(7,8)(7,9)};
\end{tikzpicture}
\end{document}


Using pgfplots:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=10,
ymin=0,ymax=10,
grid=major,
tick align=outside,
xtick={0,1,2,3,4,5,6,7,8,9,10},
ytick={0,1,2,3,4,5,6,7,8,9,10}]
coordinates {(2,5) (2,6) (2,7) (2,8) (2,9)
(3,3) (3,4) (3,5) (3,6) (3,7) (3,8) (3,9)
(5,2) (5,3) (5,4) (5,5)(5,6) (5,7) (5,8) (5,9)
(7,1)(7,2)(7,3)(7,4)(7,5)(7,6)(7,7)(7,8)(7,9)};
\end{axis}

\end{tikzpicture}
\end{document}


-

You don't really need any additional packages for such a plot, this is well within the capabilities of the base LaTeX format.

\documentclass{article}
\newcounter{c}
\begin{document}
\setlength\unitlength{1cm}

\begin{picture}(11,11)(-1,-1)
\thicklines
\put(-.2,0){\line(1,0){10.2}}
\put(0,-.2){\line(0,1){10.2}}
\thinlines
\multiput(0,-.2)(1,0){11}{%
\line(0,1){10.2}\makebox(0,0)[t]{\thec\stepcounter{c}}}
\setcounter{c}{0}
\multiput(-.2,0)(0,1){11}{%
\makebox(0,0)[r]{\thec\stepcounter{c}}\line(1,0){10.2}}

\multiput(2,5)(0,1){5}{\circle*{.2}}
\multiput(3,3)(0,1){7}{\circle*{.2}}
\multiput(5,2)(0,1){8}{\circle*{.2}}
\multiput(7,1)(0,1){9}{\circle*{.2}}
\end{picture}

\end{document}

-

Just 4 fun with the mix of PSTricks and PGF.

\documentclass[pstricks]{standalone}
\usepackage{pst-plot,pgffor}
\begin{document}
\begin{pspicture}[showgrid](-1,-1)(10,10)
\psaxes{->}(0,0)(-0.5,-0.5)(9.5,9.5)
\foreach \x/\s in {2/5,3/3,5/2,7/1}{\foreach \y in {\s,...,9}{\psdot[linecolor=blue](\x,\y)}}
\end{pspicture}
\end{document}


## Animated version:

\documentclass[pstricks]{standalone}
\usepackage{pst-plot,pgffor}
\begin{document}
\foreach \x/\s in {2/5,3/3,5/2,7/1}{\foreach \y in {\s,...,9}{%
\begin{pspicture}[showgrid=bottom](-1,-1)(10,10)
\psaxes{->}(0,0)(-0.5,-0.5)(9.5,9.5)
\pscircle*[linecolor=blue](\x,\y){3pt}
\end{pspicture}}}
\end{document}

-
You are naughty! Very naughty! –  Harish Kumar Nov 19 '12 at 1:56
@HarishKumar: Mission accomplished: The top investor –  In PSTricks we trust Nov 19 '12 at 20:53
Oho Now I see your goal! :-) –  Harish Kumar Nov 19 '12 at 22:06

This solution addresses two different and unrelated issues of the question.

## 1. The Given Data:

If I read the question correctly, the requirements are that the data is:

1. x can only go from 0 to 9, and the values of y can only go from 0 to 9.
2. The given data points are the lower bounds: (2,5), (3,3), (5,2) and (7,1).

and that the points referred to as being above these points are to be determined. That is the above points are not part of the data.

So, this solution provides a way of using just the given data:

\begin{filecontents*}{plot.dat}
2,5
3,3
5,2
7,1
\end{filecontents*}


and computing the above points.

## 2. A New Plot Method:

Well, since the others covered the usual drawing methods of pgfplots, tikz and pstricks and even the esoteric picture environment, I had to find yet another way to do that plot. And I found one: using the dataplot package from the datatool bundle.

But this method could certainly be applied to using the other methods of plotting.

So, given the above input data we obtain (points in blue show the given data, and the points in red is the extrapolated data).

## Code:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{plot.dat}
2,5
3,3
5,2
7,1
\end{filecontents*}

\usepackage{xcolor}
\usepackage{datatool}
\usepackage{dataplot}
\usepackage{pgffor}

% Specify the constraints
\newcommand*{\YMax}{9}
\newcommand*{\YMin}{0}
\newcommand*{\XMax}{9}
\newcommand*{\XMin}{0}

% Temp variable
\newcounter{StartYValue}

\begin{document}

% Now that we have the db read in, we need to create
% a db with all the points "above" these.
\DTLnewdb{myPlotDataAbove}
\DTLforeach{myPlotData}{\x=xData,\y=YData}{%
\setcounter{StartYValue}{\y}
\stepcounter{StartYValue}
\foreach \YAbove in {\arabic{StartYValue},...,\YMax} {%
\dtlexpandnewvalue
\DTLnewrow{myPlotDataAbove}
\DTLnewdbentry{myPlotDataAbove}{xData}{\x}
\DTLnewdbentry{myPlotDataAbove}{YData}{\YAbove}
}%
}

% Now plot the two db that we have.

\DTLplot{myPlotData,myPlotDataAbove}{%
x=xData, y=YData,%
minx=\XMin, maxx=\XMax, miny= \YMin, maxy= \YMax,
xticpoints={1,2,3,4,5,6,7,8},
yticpoints={1,2,3,4,5,6,7,8,9},
marks={\pgfuseplotmark{*},\pgfuseplotmark{*}},
colors={blue,red},
}
\end{document}

-

without specifieing the y coordinates because they are known: y=int(10/x)..9

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}
\begin{document}

\begin{pspicture}(-1,-1)(10,10)
\psframe*[linecolor=blue!8!white!90](9,9)
\psaxes[ticksize=0 9,tickcolor=black!20]{->}(9.5,9.5)
\psforeach{\ix}{2,3,5,7}{%
\multido{\iy=9+-1}{\numexpr10-10/\ix\relax}{%
\psdot[linecolor=blue,dotscale=2](\ix,\iy)}}
\end{pspicture}
\end{document}


with current pstricks.tex from http://texnik.dante.de/tex/generic/pstricks/

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-1,-1)(10,10)
\psaxes[ticksize=0 9,tickcolor=black!20]{->}(9.5,9.5)
\pgfforeach \x in {2,3,5,7}{%
\pgfforeach \y in {\numexpr10/\x,...,9}{%
\psdot[linecolor=blue,dotscale=2](\x,\y)}}
\end{pspicture}
\end{document}

-
I am sorry. I think renaming \foreach to \pgfforeach is not beneficial because (1) it is not consistent, PSTricks' macros should be prefixed by ps or pst, (2) typing \foreach should be shorter than \pgfforeach. But inputing pgffor by default is of course a good idea. –  In PSTricks we trust Mar 12 '13 at 17:17
foreach is not renamed! –  Herbert Mar 12 '13 at 18:25
I meant aliasing with let. –  In PSTricks we trust Mar 12 '13 at 18:33
and there are some good reason to do so ... –  Herbert Mar 12 '13 at 18:44