需要图片帮助吗(II)

需要图片帮助吗(II)

我知道我应该学习 TikZ......我需要帮助来画出这张非常简单的图片(有两种颜色,红色和蓝色,它是一个论点的例证,所描绘的情况是 n=3)。

如果有人能给我代码,我将非常感激。否则,我将使用黑白的 xfig 做点什么。提前致谢。

答案1

就这样 :) 正如你所说,你想学习 tikz,我或多或少地对所有内容进行了评论,以便你有一个参考。如果你对代码的某个部分有疑问,请随时提问!这是结果:

在此处输入图片描述

代码如下:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}
        %- Draw blue part
        \begin{scope}[color = blue]
            \draw[-latex] (0,0) -- (1.25,0); % X - axis
            \draw[-latex] (0,0) -- (0,1.25); % Y - axis
            \draw[] (1,0) -- (1,1);
            \draw[] (0,1) -- (1,1);
            \node [below,left] () at (0,0) { \tiny (0,0)};
            \node [above,right] () at (1,1) { \tiny (1,1)};
        \end{scope}
        
        %- Draw red part
        \begin{scope}[color = red]
            \node[below] (xPoint) at (1/3,0){\tiny $\frac{1}{n}$}; % Label on x axis
            \node[left] (yPoint) at (0,2/3){\tiny 1-$\frac{1}{n}$}; % Label on y axis
            \draw[dashed] (xPoint) -- (1/3,2/3); % Line between x axis and (1/3,2/3)
            \draw[dashed] (yPoint) -- (1/3,2/3); % Line between y axis and (1/3,2/3)
            \fill (0,0) circle (1pt); % Red circle at (0,0)
            \fill (1/3,2/3) circle (1pt); 
            \fill (1,1) circle (1pt); 
            \draw (0,0) -- (1/3,2/3) -- (1,1) node[midway,below] (){\tiny $\varphi_n$};
            % In the draw command above, I have created the text by writing a node in the middle of the last segment
        \end{scope}
        
    \end{tikzpicture}
\end{document}

答案2

一个简短的答案是使用节点动态。并且改变值的可能性n

\documentclass[tikz,border=3.141592mm]{standalone}
\usepackage{amsmath}

\begin{document}
    \def\n{3}
    \begin{tikzpicture}[cyan,scale=4,pn/.style={circle,inner sep=0pt,minimum width=2pt,fill=red}]
        \draw[->] (-.1,0) -- (1.2,0);
        \draw[->] (0,-.1) -- (0,1.2);
        \draw[densely dashed] (0,1) -| (1,0);
        \draw[red] (0,0) node[pn] {}  node[cyan,below left] {$(0\,,0)$} -- (1/\n,1-1/\n) node[pn] {} -- (1,1) node[midway,below] {$\varphi_n$} node[pn] {} node[cyan,above right] {$(1\,,1)$};
        \draw[red,densely dotted] (0,1-1/\n) node[left] {$1-\dfrac{1}{n}$} -| (1/\n,0) node[below] {$\dfrac{1}{n}$};
    \end{tikzpicture}
\end{document}

非常简单的图表

相关内容