图中标示要求

图中标示要求

我正在画两条相交线的图。我只想用箭头符号表示,或者只是突出显示红线与蓝线相交的 $n=6$。

先感谢您

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[x=3mm,y=1mm]
\draw[thin,gray!40,xstep=2,ystep=5] (0,0) grid (32,140);
\draw(0,0) -- (0,140) -- ++(0.5,0)node[left=1.2cm,below=6cm]{$E(G)$};
\foreach \y in {5,10,...,140}{
\draw(0,\y)--+(0.5,0)node[left=4pt]{\footnotesize\textsf{\y}};}
\draw(0,0) -- (32,0) node[left=5cm,below=5mm]{$n$} -- ++(0,1.5);
\foreach \x in {2,4,6,8,...,32}{
\draw(\x,0)--+(0,1.5)node[below=5pt]{\footnotesize\textsf{\x}};
}
\begin{scope}
\clip(0,0) rectangle (32,140);
\draw[blue,thick] (1,4*1-2) -- node[pos=.5,below,sloped,black]{$Y$} (32,4*32-2);
\draw[red,thick] (1,4.4722*1-4.4722) -- node[pos=0.5,sloped,above,black]{$X$} (32, 4.4722*32-4.4722);
\end{scope}
\end{tikzpicture}
\end{document}

答案1

  • 我建议使用该pgfplots包。
  • 您使用纯净的tikz/pgf解决方案 - 有什么特别的原因吗?
  • 我只是给了你一个起点,并没有做精确的计算。

\documentclass[border=5pt,varwidth,tikz]{standalone}

% Your Solution
\usepackage{tikz}
\usetikzlibrary{calc}

% My Proposal
\usepackage{pgfplots}

\begin{document}

% Your Solution
\begin{tikzpicture}[x=3mm,y=1mm]
\draw[thin,gray!40,xstep=2,ystep=5] (0,0) grid (32,140);
\draw(0,0) -- (0,140) -- ++(0.5,0)node[left=1.2cm,below=6cm]{$E(G)$};
\foreach \y in {5,10,...,140}{
\draw(0,\y)--+(0.5,0)node[left=4pt]{\footnotesize\textsf{\y}};}
\draw(0,0) -- (32,0) node[left=5cm,below=5mm]{$n$} -- ++(0,1.5);
\foreach \x in {2,4,6,8,...,32}{
\draw(\x,0)--+(0,1.5)node[below=5pt]{\footnotesize\textsf{\x}};
}
\begin{scope}
\clip(0,0) rectangle (32,140);
\draw[blue,thick] (1,4*1-2) -- node[pos=.5,below,sloped,black]{$Y$} (32,4*32-2);
\draw[red,thick] (1,4.4722*1-4.4722) -- node[pos=0.5,sloped,above,black]{$X$} (32, 4.4722*32-4.4722);
\end{scope}
\end{tikzpicture}

% My Proposal

\begin{tikzpicture}
    \begin{axis}[
        xlabel = {n},
        ylabel = {$E(n)$},
        width = 100mm,
        height = 60mm,
        xmin = 0,
        xmax = 30,
        ymin = 0,
        ymax = 100,
    ]
    % Line 1
    \addplot[
        no marks,
        line width = 1pt, 
        color=blue,
        domain = 0:30,
        ]
        {1.5*x+4};
    % Line 2
    \addplot[
        no marks,
        line width = 1pt, 
        color=red,
        domain = 0:30,      
        ]
        {2.2*x+1};      
    % Annotations
    \node[fill=black,circle,scale=0.3,pin=0:{$X$}] at (axis cs:5,60) {};
    \node[fill=black,circle,scale=0.3,pin=60:{$Y$}] at (axis cs:10,40) {};
    \node[fill=black,circle,scale=0.3,pin=120:{Intersection}] at (axis cs:25,50) {};
    \end{axis}
\end{tikzpicture}

你的代码

在此处输入图片描述

我的建议

在此处输入图片描述

相关内容