如何创建此图像(绘图)

如何创建此图像(绘图)

我想创建一个只有第一象限的图表。x 的值只能从 0 到 9,y 的值只能从 0 到 9。在此图表中,我想要 (2,5)、(3,3)、(5,2) 和 (7,1) 的点。在指定的每对上方,我想要其上方的点。例如,(2,5) 上方的点是 (2,6)、(2,7)、(2,8) 和 (2,9)。有人知道怎么做吗?

答案1

通过 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};
    }
  \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}

在此处输入图片描述

使用plot功能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}

使用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}]
\addplot+[only marks]
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}

在此处输入图片描述

答案2

对于这样的绘图,您实际上不需要任何额外的包,这完全在基本 LaTeX 格式的功能范围内。

在此处输入图片描述

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

答案3

只需将 PSTricks 与 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}

动画版:

在此处输入图片描述

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

答案4

无需指定 y 坐标,因为它们是已知的: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}

在此处输入图片描述

与当前pstricks.tex来自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}

相关内容