绘制一个tikz完整的12个节点有向图

绘制一个tikz完整的12个节点有向图

我需要使用 Tikz 绘制基于音乐理论的图表。如标题所述,这是一个 12 节点的完整有向图。节点必须根据音符标记,边必须根据音程标记。我有一个手绘示例,说明了我需要的内容:图表示例

在图像上我只画了一些边,因为画出每一条边会很乱。但正如之前所说,它应该是完整的。

我希望可以这样标记每条边。我也希望我的问题足够清楚。谢谢!

答案1

你说得很对,这确实很乱。我画的方式是,在三全音线之后用直线画,这样画出来的线开始重叠,所以我建议画两个单独的图表,分别表示大二度到三全音,然后是三全音到大七度。

因此,第一个大二度到三全音的图表将给出 12 个音符之间的连通图,显示从小二度到三全音的音程

给出的是

\documentclass[tikz, border=20]{standalone}

\usepackage{contour}  % Add halo around node text for readability

\pgfdeclarelayer{foreground}  % nodes placed in foreground
\pgfsetlayers{main,foreground}

\pgfmathsetmacro{\R}{7}

\contourlength{1.2pt}
\begin{document}
    \begin{tikzpicture}
        \tikzset{note/.style={draw, circle, minimum size=1.75cm}}
        \tikzset{edge/.style={->, >=latex}}
        
        \node[note] (C) at (0:\R) {C};
        \node[note] (Db) at (-30:\R) {C\#/Db};
        \node[note] (D) at (-60:\R) {D};
        \node[note] (Eb) at (-90:\R) {D\#/Eb};
        \node[note] (E) at (-120:\R) {E};
        \node[note] (F) at (-150:\R) {F};
        \node[note] (Gb) at (-180:\R) {F\#/Gb};
        \node[note] (G) at (-210:\R) {G};
        \node[note] (Ab) at (-240:\R) {G\#/Ab};
        \node[note] (A) at (-270:\R) {A};
        \node[note] (Bb) at (-300:\R) {A\#/Bb};
        \node[note] (B) at (-330:\R) {B};
        
        % Minor seconds
        \foreach \i/\j in {C/Db, Db/D, D/Eb, Eb/E, E/F, F/Gb, Gb/G, G/Ab, Ab/A, A/Bb, Bb/B, B/C} {
            \draw[edge] (\i) -- (\j);
            \begin{pgfonlayer}{foreground}
                 \path (\i) -- (\j) node[midway] {\contour{white}{2m}};
            \end{pgfonlayer}
        }
        
        % Major seconds
        \foreach \i/\j in {C/D, Db/Eb, D/E, Eb/F, E/Gb, F/G, Gb/Ab, G/A, Ab/Bb, A/B, Bb/C, B/Db} {
            \draw[edge] (\i) -- (\j);
            \begin{pgfonlayer}{foreground}
                \path (\i) -- (\j) node[midway] {\contour{white}{2M}};
            \end{pgfonlayer}
        }
        
        % Minor thirds
        \foreach \i/\j in {C/Eb, Db/E, D/F, Eb/Gb, E/G, F/Ab, Gb/A, G/Bb, Ab/B, A/C, Bb/Db, B/D} {
            \draw[edge] (\i) -- (\j);
            \begin{pgfonlayer}{foreground}
                \path (\i) -- (\j) node[midway] {\contour{white}{3m}};
            \end{pgfonlayer}
        }
        
        % Major thirds
        \foreach \i/\j in {C/E, Db/F, D/Gb, Eb/G, E/Ab, F/A, Gb/Bb, G/B, Ab/C, A/Db, Bb/D, B/Eb} {
            \draw[edge] (\i) -- (\j);
            \begin{pgfonlayer}{foreground}
                 \path (\i) -- (\j) node[midway] {\contour{white}{3M}};
            \end{pgfonlayer}
        }
        
        % Perfect Fourths
        \foreach \i/\j in {C/F, Db/Gb, D/G, Eb/Ab, E/A, F/Bb, Gb/B, G/C, Ab/Db, A/D, Bb/Eb, B/E} {
            \draw[edge] (\i) -- (\j);
            \begin{pgfonlayer}{foreground}
                 \path (\i) -- (\j) node[midway] {\contour{white}{4}};
            \end{pgfonlayer}
        }
        
        % Tritones
        \foreach \i/\j in {C/Gb, Db/G, D/Ab, Eb/A, E/Bb, F/B, Gb/C, G/Db, Ab/D, A/Eb, Bb/E, B/Eb} {
            \draw[edge] (\i) -- (\j);
            \begin{pgfonlayer}{foreground}
                 \path (\i) -- (\j) node[midway] {\contour{white}{T}};
            \end{pgfonlayer}
        }
    \end{tikzpicture}
\end{document}

三全音到大七度的图表如下 12 个音符之间的连通图,显示从三全音到大七度的音程 下文使用相同的序言给出

\begin{tikzpicture}
    \tikzset{note/.style={draw, circle, minimum size=1.75cm}}
    \tikzset{edge/.style={<-, >=latex}}
    
    \node[note] (C) at (0:\R) {C};
    \node[note] (Db) at (-30:\R) {C\#/Db};
    \node[note] (D) at (-60:\R) {D};
    \node[note] (Eb) at (-90:\R) {D\#/Eb};
    \node[note] (E) at (-120:\R) {E};
    \node[note] (F) at (-150:\R) {F};
    \node[note] (Gb) at (-180:\R) {F\#/Gb};
    \node[note] (G) at (-210:\R) {G};
    \node[note] (Ab) at (-240:\R) {G\#/Ab};
    \node[note] (A) at (-270:\R) {A};
    \node[note] (Bb) at (-300:\R) {A\#/Bb};
    \node[note] (B) at (-330:\R) {B};
    
    % Major sevenths
    \foreach \i/\j in {C/Db, Db/D, D/Eb, Eb/E, E/F, F/Gb, Gb/G, G/Ab, Ab/A, A/Bb, Bb/B, B/C} {
        \draw[edge] (\i) -- (\j);
        \begin{pgfonlayer}{foreground}
             \path (\i) -- (\j) node[midway] {\contour{white}{7M}};
        \end{pgfonlayer}
    }
    
    % Minor sevenths
    \foreach \i/\j in {C/D, Db/Eb, D/E, Eb/F, E/Gb, F/G, Gb/Ab, G/A, Ab/Bb, A/B, Bb/C, B/Db} {
        \draw[edge] (\i) -- (\j);
        \begin{pgfonlayer}{foreground}
            \path (\i) -- (\j) node[midway] {\contour{white}{7m}};
        \end{pgfonlayer}
    }
    
    % Major sixths
    \foreach \i/\j in {C/Eb, Db/E, D/F, Eb/Gb, E/G, F/Ab, Gb/A, G/Bb, Ab/B, A/C, Bb/Db, B/D} {
        \draw[edge] (\i) -- (\j);
        \begin{pgfonlayer}{foreground}
            \path (\i) -- (\j) node[midway] {\contour{white}{6M}};
        \end{pgfonlayer}
    }
    
    % Minor Sixths
    \foreach \i/\j in {C/E, Db/F, D/Gb, Eb/G, E/Ab, F/A, Gb/Bb, G/B, Ab/C, A/Db, Bb/D, B/Eb} {
        \draw[edge] (\i) -- (\j);
        \begin{pgfonlayer}{foreground}
             \path (\i) -- (\j) node[midway] {\contour{white}{6m}};
        \end{pgfonlayer}
    }
    
    % Perfect Fifths
    \foreach \i/\j in {C/F, Db/Gb, D/G, Eb/Ab, E/A, F/Bb, Gb/B, G/C, Ab/Db, A/D, Bb/Eb, B/E} {
        \draw[edge] (\i) -- (\j);
        \begin{pgfonlayer}{foreground}
             \path (\i) -- (\j) node[midway] {\contour{white}{5}};
        \end{pgfonlayer}
    }
    
    % Tritones
    \foreach \i/\j in {C/Gb, Db/G, D/Ab, Eb/A, E/Bb, F/B, Gb/C, G/Db, Ab/D, A/Eb, Bb/E, B/Eb} {
        \draw[edge] (\i) -- (\j);
        \begin{pgfonlayer}{foreground}
             \path (\i) -- (\j) node[midway] {\contour{white}{T}};
        \end{pgfonlayer}
    }
\end{tikzpicture}

不过我个人认为这仍然很混乱,我不知道你用它做什么,但我个人会选择颜色编码方案。你也可以使用虚线/点线等进行黑白打印/色盲友好版本。下图给出了箭头的向前方向,然后在括号中(对于美国人来说是圆括号)给出了向后方向:

12 个音符之间的连通图显示彩虹中的间隔

这是由

\begin{tikzpicture}
    \tikzset{note/.style={draw, circle, minimum size=1.75cm}}
    \tikzset{edge/.style={->, >=latex}}
    
    \node[note] (C) at (0:\R) {C};
    \node[note] (Db) at (-30:\R) {C\#/Db};
    \node[note] (D) at (-60:\R) {D};
    \node[note] (Eb) at (-90:\R) {D\#/Eb};
    \node[note] (E) at (-120:\R) {E};
    \node[note] (F) at (-150:\R) {F};
    \node[note] (Gb) at (-180:\R) {F\#/Gb};
    \node[note] (G) at (-210:\R) {G};
    \node[note] (Ab) at (-240:\R) {G\#/Ab};
    \node[note] (A) at (-270:\R) {A};
    \node[note] (Bb) at (-300:\R) {A\#/Bb};
    \node[note] (B) at (-330:\R) {B};
    
    % Minor seconds
    \foreach \i/\j in {C/Db, Db/D, D/Eb, Eb/E, E/F, F/Gb, Gb/G, G/Ab, Ab/A, A/Bb, Bb/B, B/C} {
        \draw[edge, red] (\i) -- (\j);
    }
    
    % Major seconds
    \foreach \i/\j in {C/D, Db/Eb, D/E, Eb/F, E/Gb, F/G, Gb/Ab, G/A, Ab/Bb, A/B, Bb/C, B/Db} {
        \draw[edge, orange] (\i) -- (\j);
    }
    
    % Minor thirds
    \foreach \i/\j in {C/Eb, Db/E, D/F, Eb/Gb, E/G, F/Ab, Gb/A, G/Bb, Ab/B, A/C, Bb/Db, B/D} {
        \draw[edge, yellow] (\i) -- (\j);
    }
    
    % Major thirds
    \foreach \i/\j in {C/E, Db/F, D/Gb, Eb/G, E/Ab, F/A, Gb/Bb, G/B, Ab/C, A/Db, Bb/D, B/Eb} {
        \draw[edge, green] (\i) -- (\j);
    }
    
    % Perfect Fourths
    \foreach \i/\j in {C/F, Db/Gb, D/G, Eb/Ab, E/A, F/Bb, Gb/B, G/C, Ab/Db, A/D, Bb/Eb, B/E} {
        \draw[edge, blue] (\i) -- (\j);
    }
    
    % Tritones
    \foreach \i/\j in {C/Gb, Db/G, D/Ab, Eb/A, E/Bb, F/B, Gb/C, G/Db, Ab/D, A/Eb, Bb/E, B/Eb} {
        \draw[edge, red!50!blue] (\i) -- (\j);
    }
    \foreach \y/\col/\lab in {1/red/Minor Second (Major Seventh), 2/orange/Major Second (Minor Seventh), 3/yellow/Minor Third (Major Sixth), 4/green/Major Third (Minor Sixth), 5/blue/Perfect Fourth (Perfect Fifth), 6/red!50!blue/Tritone} {
        \draw[ultra thick, color=\col] (-3, -\R-1-\y) -- (-2, -\R-1-\y) node[right, black] {\lab};
    }
\end{tikzpicture}

相关内容