使用 tikz 在散点图的 x 轴上生成随机“标记”

使用 tikz 在散点图的 x 轴上生成随机“标记”

我生成了以下散点图 enter image description here

使用此代码

\documentclass[danish,a4paper,12pt]{article}
\usepackage{pgf,tikz}
\begin{document}
\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
    \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=12.092605737472649cm,y=374.6606503225678cm]
    \draw[->,color=black] (0.,0.) -- (0.85,0);
    \foreach \x in {,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8}
    \draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
    \draw[->,color=black] (0.,0.) -- (0.,0.02669082005647084);
    \foreach \y in {0.005,0.01,0.015,0.02,0.025}
    \draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
    \draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
    \clip(0.,0.) rectangle (0.8269516278871089,0.02669082005647084);
    \begin{scriptsize}
    \draw [fill=uuuuuu] (0.,0.) circle (1.5pt);
    \draw [fill=uuuuuu] (0.0326,0.00599337793538) circle (1.5pt);
    \draw [fill=uuuuuu] (0.066567,0.00800334092061) circle (1.5pt);
    \draw [fill=uuuuuu] (0.099533,0.0118183240821) circle (1.5pt);
    \draw [fill=uuuuuu] (0.1335,0.0162894171978) circle (1.5pt);
    \draw [fill=uuuuuu] (0.166467,0.0199695510686) circle (1.5pt);
    \draw [fill=uuuuuu] (0.199433,0.0224502399865) circle (1.5pt);
    \draw [fill=uuuuuu] (0.2334,0.0232532463933) circle (1.5pt);
    \draw [fill=uuuuuu] (0.266367,0.0234484998458) circle (1.5pt);
    \draw [fill=uuuuuu] (0.300333,0.0235156791863) circle (1.5pt);
    \draw [fill=uuuuuu] (0.3333,0.0236558243653) circle (1.5pt);
    \draw [fill=uuuuuu] (0.366267,0.0240320568046) circle (1.5pt);
    \draw [fill=uuuuuu] (0.400233,0.0237211598547) circle (1.5pt);
    \draw [fill=uuuuuu] (0.4332,0.0228133071563) circle (1.5pt);
    \draw [fill=uuuuuu] (0.467167,0.022779717486) circle (1.5pt);
    \draw [fill=uuuuuu] (0.500133,0.0226828018266) circle (1.5pt);
    \draw [fill=uuuuuu] (0.5331,0.0224762107547) circle (1.5pt);
    \draw [fill=uuuuuu] (0.567067,0.0230861344422) circle (1.5pt);
    \draw [fill=uuuuuu] (0.600033,0.0239829235302) circle (1.5pt);
    \draw [fill=uuuuuu] (0.634,0.0237828910273) circle (1.5pt);
    \draw [fill=uuuuuu] (0.666967,0.0230542213422) circle (1.5pt);
    \draw [fill=uuuuuu] (0.699933,0.023526158748) circle (1.5pt);
    \draw [fill=uuuuuu] (0.7339,0.0235532932594) circle (1.5pt);
    \draw [fill=uuuuuu] (0.766867,0.0228133071554) circle (1.5pt);
    \end{scriptsize}
    \end{tikzpicture}
\end{document}

但是正如您在右下角看到的,有一个随机标记超出了该线的范围,我无论如何也看不出代码中是什么强制了这个标记。

答案1

一般来说,使用正常或对数缩放绘制函数图时,如果你使用pgf图包。它基于 TikZ,设计用于绘制线、散点图、条形图、网格图和类似图的用户友好界面。通过它,您的 MWE 可以如下:

\documentclass[danish,a4paper,12pt]{article}
    \usepackage{pgf,tikz}
    \usepackage{pgfplots}
    \pgfplotsset{compat=newest} 

\definecolor{uuuuuu}{rgb}{0.266,0.266,0.266}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[ 
width=85mm, height=50mm,
  scaled y ticks = false,% xmin = 0.00,  ymin = 0.0,
yticklabel style = {/pgf/number format/fixed,
                     /pgf/number format/precision=3},
tick label style = {font=\footnotesize},
scale only axis,
xmax = 0.85,ymax = 0.028,
      axis lines = left,
      xlabel = {$x$},
      ylabel = {$y$}
            ]
\addplot[only marks,mark size=1.5pt] coordinates {
    (0.0,0.0)
    (0.0326,0.00599337793538)
    (0.066567,0.00800334092061)
    (0.099533,0.0118183240821)
    (0.1335,0.0162894171978)
    (0.166467,0.0199695510686)
    (0.199433,0.0224502399865)
    (0.2334,0.0232532463933)
    (0.266367,0.0234484998458)
    (0.300333,0.0235156791863)
    (0.3333,0.0236558243653)
    (0.366267,0.0240320568046)
    (0.400233,0.0237211598547)
    (0.4332,0.0228133071563)
    (0.467167,0.022779717486)
    (0.500133,0.0226828018266)
    (0.5331,0.0224762107547)
    (0.567067,0.0230861344422)
    (0.600033,0.0239829235302)
    (0.634,0.0237828910273)
    (0.666967,0.0230542213422)
    (0.699933,0.023526158748)
    (0.7339,0.0235532932594)
    (0.766867,0.0228133071554)
    };
\end{axis}
    \end{tikzpicture}
\end{document}

这使:

enter image description here

顺便说一句,在绘制图表时没有必要夸大坐标精度。在大多数情况下,1% 的精度已经足够了。

答案2

如上所述,由于缺少库,您的代码无法编译。一旦弥补了这一缺陷,MWE 可以简化为:

\documentclass[tikz,border=10pt,12pt]{standalone}
\usetikzlibrary{arrows}% deprecated - consider arrows.meta instead
\begin{document}
\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
\begin{tikzpicture}[line cap=round, line join=round, >=triangle 45, x=12.092605737472649cm, y=374.6606503225678cm]
  \draw[->,color=black] (0.,0.) -- (0.85,0);
      \foreach \x in {,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8}
      \draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\end{tikzpicture}
\end{document}

stray mark

杂散标记是由循环值集合中的杂散逗号引起的。更正后的代码:

\documentclass[tikz,border=10pt,12pt]{standalone}
\usetikzlibrary{arrows}% deprecated - consider arrows.meta instead
\begin{document}
\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
\begin{tikzpicture}[line cap=round, line join=round, >=triangle 45, x=12.092605737472649cm, y=374.6606503225678cm]
  \draw[->,color=black] (0.,0.) -- (0.85,0);
      \foreach \x in {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8}
      \draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\end{tikzpicture}
\end{document}

correct output

相关内容