我正在这样做:
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz,amsmath}
\usetikzlibrary{arrows}%
\usepackage[np,autolanguage]{numprint}
\begin{document}
\begin{tikzpicture}%
\draw[step=1cm,black,thin] (0,0) grid (5,5);
%\foreach \x in {0, 1,...,5} { \node [anchor=north] at (\x,-0.2) {0.0}; }
%\foreach \y in {0, 1,...,5} { \node [anchor=east] at (-0.2,\y) {\y}; }
\node at (-0.5,0) {0.0};
\node at (-0.5,1) {0.2};
\node at (-0.5,2) {0.4};
\node at (-0.5,3) {0.6};
\node at (-0.5,4) {0.8};
\node at (-0.5,5) {1.0};
\node at (0,-0.5) {0.0};
\node at (1,-0.5) {0.2};
\node at (2,-0.5) {0.4};
\node at (3,-0.5) {0.6};
\node at (4,-0.5) {0.8};
\node at (5,-0.5) {1.0};
\draw [fill=black, thin] (0.5,2.5) circle [radius=0.05];
\draw [fill=black, thin] (1.5,0.5) circle [radius=0.05];
\draw [fill=black, thin] (2.5,4.5) circle [radius=0.05];
\draw [fill=black, thin] (3.5,1.5) circle [radius=0.05];
\draw [fill=black, thin] (4.5,3.5) circle [radius=0.05];
\end{tikzpicture}%
\end{document}
请告诉我有没有更好的方法来编号网格(而不是编号单个节点)并一次绘制多个圆圈!
谢谢。
答案1
您是否希望对所有内容进行简单的 foreach? 您可以使用以下代码完成相同的操作
% arara: pdflatex
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=1cm,black,thin] (0,0) grid (5,5);
\foreach \xtick in {0,...,5} {\pgfmathsetmacro\result{\xtick * .2} \node at (\xtick,-0.5) {\pgfmathprintnumber{\result}}; }
\foreach \ytick in {0,...,5} {\pgfmathsetmacro\result{\ytick * .2} \node at (-.5,\ytick) {\pgfmathprintnumber{\result}}; }
\foreach \x/\y in {.5/2.5, 1.5/.5, 2.5/4.5, 3.5/1.5, 4.5/3.5}{\draw [fill=black, thin] (\x,\y) circle [radius=0.05];}
\end{tikzpicture}
\end{document}
如果您想要更聪明的东西,您必须在这里解释您想要展示的技术。
below
节点可以随意放置left
。无需硬编码。
如果你要绘制更多数据,你pgfplots
当然应该这样做:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
,x=5cm,y=5cm
,grid=major
,major grid style={thick,black}
,xmin=0, xmax=1
,ymin=0, ymax=1
]
\addplot[black, mark=*, only marks] table {
.1 .5
.3 .1
.5 .9
.7 .3
.9 .7
};
\end{axis}
\end{tikzpicture}
\end{document}