我正在尝试在 Latex 中创建一个具有大量边的图形。类似于所附图像(取自 Bissyandé 等人的论文)。
我试图使用 tikzpicture 和一些边简单地绘制一个图形,但是如何从外部文件(CSV?!)导入边以及如何根据值更改边的粗细?
这是我迄今为止所做的起点:
\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
\node [style=none] (0) at (-1.25, 4.5) {C};
\node [style=none] (1) at (3.5, 4.5) {C++};
\node [style=none] (2) at (3.5, 2.5) {HTML};
\node [style=none] (3) at (-2.75, 2.5) {JavaScript};
\node [style=none] (4) at (1.25, 5) {Python};
\node [style=none] (5) at (1.25, 1.75) {CSS};
\node [style=none] (6) at (3.75, 6) {Shell};
\node [style=none] (7) at (-2.25, 5.75) {Objective-C};
\node [style=none] (8) at (1.75, -0.5) {PHP};
\node [style=none] (9) at (5, 0) {Java};
\node [style=none] (10) at (5.25, 3.5) {Makefile};
\node [style=none] (11) at (-1.75, 0) {Ruby};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw (0.center) to (3.center);
\draw (0.center) to (2.center);
\draw (2.center) to (1.center);
\draw (3.center) to (1.center);
\draw (11.center) to (5.center);
\draw (11.center) to (3.center);
\draw (11.center) to (0.center);
\draw (8.center) to (0.center);
\draw (7.center) to (0.center);
\draw (4.center) to (5.center);
\draw (0.center) to (4.center);
\draw (4.center) to (1.center);
\draw (6.center) to (10.center);
\draw (10.center) to (9.center);
\draw (9.center) to (2.center);
\draw (2.center) to (10.center);
\draw (8.center) to (5.center);
\draw (8.center) to (2.center);
\end{pgfonlayer}
\end{tikzpicture}
谢谢!
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-network}
\begin{filecontents}{vertices.csv}
id, x, y ,label
0, -1.25, 4.5, C
1, 3.5, 4.5, C++
2, 3.5, 2.5, HTML
3, -2.75, 2.5, JavaScript
4, 1.25, 5, Python
5, 1.25, 1.75, CSS
6, 3.75, 6, Shell
7, -2.25, 5.75, Objective-C
8, 1.75, -0.5, PHP
9, 5, 0, Java
10, 5.25, 3.5, Makefile
11, -1.75, 0, Ruby
\end{filecontents}
\begin{filecontents}{edges.csv}
u, v, lw
0, 3, 1
0, 2, 2
2, 1, 1
3, 1, 5
11, 5, 1
11, 3, 10
11, 0, 1
8, 0, 1
7, 0, 1
4, 5, 8
0, 4, 1
4, 1, 1
6, 10, 1
10, 9, 3
9, 2, 1
2, 10, 1
8, 5, 1
8, 2, 1
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\Vertices[size=0, style={inner sep=0pt}]{vertices.csv}
\Edges[color=lightgray]{edges.csv}
\end{tikzpicture}
\end{document}