![节点填充的颜色遮挡了该图的节点标签](https://linux22.com/image/458673/%E8%8A%82%E7%82%B9%E5%A1%AB%E5%85%85%E7%9A%84%E9%A2%9C%E8%89%B2%E9%81%AE%E6%8C%A1%E4%BA%86%E8%AF%A5%E5%9B%BE%E7%9A%84%E8%8A%82%E7%82%B9%E6%A0%87%E7%AD%BE.png)
背景:我正在使用tikzplotlib
将图转换plt
为tikz
。我将其应用于随机图网络,如下所示。
考虑以下 tikz 代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-graph}
\usetikzlibrary{fit}
\usetikzlibrary{backgrounds}
\usepackage{pgfplots}
\begin{document}
% This file was created with tikzplotlib v0.10.1.
\begin{tikzpicture}
\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{steelblue31120180}{RGB}{31,120,180}
\begin{axis}[
hide x axis,
hide y axis,
scaled x ticks=manual:{}{\pgfmathparse{##1}},
scaled y ticks=manual:{}{\pgfmathparse{##1}},
tick align=outside,
x grid style={darkgray176},
xmajorticks=false,
xmin=-0.56233709013339, xmax=0.562444553413885,
xtick style={color=black},
xticklabels={},
y grid style={darkgray176},
ymajorticks=false,
ymin=-1.20947471305574, ymax=1.20995008585598,
ytick style={color=black},
yticklabels={}
]
\path [draw=black]
(axis cs:0.464839534758957,0.108082528289179)
--(axis cs:-0.464732071478461,-0.108557901089417);
\path [draw=black]
(axis cs:0.464839534758957,0.108082528289179)
--(axis cs:0.232917848079166,-0.999524627199763);
\path [draw=black]
(axis cs:0.464839534758957,0.108082528289179)
--(axis cs:-0.233025311359662,1);
\path [draw=black]
(axis cs:0.232917848079166,-0.999524627199763)
--(axis cs:-0.464732071478461,-0.108557901089417);
\path [draw=black]
(axis cs:-0.464732071478461,-0.108557901089417)
--(axis cs:-0.233025311359662,1);
\addplot [draw=steelblue31120180, fill=steelblue31120180, mark=*, only marks,mark options={scale=3}]
table{%
x y
0.464839534758957 0.108082528289179
0.232917848079166 -0.999524627199763
-0.464732071478461 -0.108557901089417
-0.233025311359662 1
};
\draw (axis cs:0.464839534758957,0.108082528289179) node[
scale=1,
text=black,
rotate=0.0
]{0};
\draw (axis cs:0.232917848079166,-0.999524627199763) node[
scale=1,
text=black,
rotate=0.0
]{1};
\draw (axis cs:-0.464732071478461,-0.108557901089417) node[
scale=1,
text=black,
rotate=0.0
]{2};
\draw (axis cs:-0.233025311359662,1) node[
scale=1,
text=black,
rotate=0.0
]{3};
\end{axis}
\end{tikzpicture}
\end{document}
这应该会产生以下内容:
代替:
我们如何才能使节点标签出现?(在 Python 代码中,我确实指出要使节点标签如第二张图所示出现)
答案1
尝试此代码,在绘制完成后添加节点的内容。
\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-graph}
\usetikzlibrary{fit}
\usetikzlibrary{backgrounds}
\usepackage{pgfplots}
\begin{document}
% This file was created with tikzplotlib v0.10.1.
\begin{tikzpicture} [plotstyle/.style={ scale=1,text=black,rotate=0.0}] % changed <<<<<<<<<<<
\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{steelblue31120180}{RGB}{31,120,180}
\begin{axis}[
hide x axis,
hide y axis,
scaled x ticks=manual:{}{\pgfmathparse{##1}},
scaled y ticks=manual:{}{\pgfmathparse{##1}},
tick align=outside,
x grid style={darkgray176},
xmajorticks=false,
xmin=-0.56233709013339, xmax=0.562444553413885,
xtick style={color=black},
xticklabels={},
y grid style={darkgray176},
ymajorticks=false,
ymin=-1.20947471305574, ymax=1.20995008585598,
ytick style={color=black},
yticklabels={}
]
\path [draw=black]
(axis cs:0.464839534758957,0.108082528289179)
--(axis cs:-0.464732071478461,-0.108557901089417);
\path [draw=black]
(axis cs:0.464839534758957,0.108082528289179)
--(axis cs:0.232917848079166,-0.999524627199763);
\path [draw=black]
(axis cs:0.464839534758957,0.108082528289179)
--(axis cs:-0.233025311359662,1);
\path [draw=black]
(axis cs:0.232917848079166,-0.999524627199763)
--(axis cs:-0.464732071478461,-0.108557901089417);
\path [draw=black]
(axis cs:-0.464732071478461,-0.108557901089417)
--(axis cs:-0.233025311359662,1);
\addplot [draw=steelblue31120180, fill=steelblue31120180, mark=*, only marks,mark options={scale=3}]
table{%
x y
0.464839534758957 0.108082528289179
0.232917848079166 -0.999524627199763
-0.464732071478461 -0.108557901089417
-0.233025311359662 1
};
\draw (axis cs:0.464839534758957,0.108082528289179) node(0){}; % changed <<<<<<<<<
\draw (axis cs:0.232917848079166,-0.999524627199763) node(1){};
\draw (axis cs:-0.464732071478461,-0.108557901089417) node(2){};
\draw (axis cs:-0.233025311359662,1) node(3) {};
\end{axis}
\draw node[plotstyle] at (0) {0} node[plotstyle] at (1) {1} node[plotstyle] at (2) {2} node[plotstyle] at (3) {3};% added <<<<
\end{tikzpicture}
\end{document}