条形图中缺少标签

条形图中缺少标签

我正在尝试绘制条形图,但我加下划线并涂成绿色的文本似乎没有显示。

看起来就是这样的。

在此处输入图片描述

以下是代码。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\newcommand{\ImageWidth}{11cm}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,positioning, arrows.meta}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}[ht]
\centering
\scalebox{0.72}{ % Adjust the scale factor as needed
\begin{tikzpicture}
\begin{axis}[ 
height=19.58cm,
width=15.44cm,
xbar, xmin=-1000, xmax=25000,
xlabel={Time elapsed since the first kernel driver (module) was unloaded (in seconds)},
symbolic y coords={
    \underline{\textcolor{red}{mdd.sys}},
    \underline{\textcolor{red}{Beep.SYS$^4$}},
    \underline{\textcolor{red}{Beep.SYS$^3$}},
    \underline{\textcolor{red}{Beep.SYS$^2$}},
    \underline{\textcolor{red}{Beep.SYS$^1$}},
    \underline{\textcolor{red}{imapi.sys}},
    \underline{\textcolor{red}{processr.sys}},
    \underline{\textcolor{red}{Cdaudio.SYS}},
    \underline{\textcolor{red}{Sfloppy.SYS}},
    \underline{\textcolor{green}{kmixer.sys}},
    \underline{\textcolor{green}{drmkaud.sys}},
    \underline{\textcolor{green}{DMusic.sys}},
    \underline{\textcolor{green}{aec.sys}},
    \underline{\textcolor{green}{swmidi.sys}},
    \underline{\textcolor{green}{splitter.sys}},
    \underline{\textcolor{green}{Serial.SYS}},
    \underline{\textcolor{green}{Parport.SYS}},
    \underline{\textcolor{green}{imapi.sys}},
    \underline{\textcolor{green}{redbook.sys}},
    \underline{\textcolor{green}{intelppm.sys}},
    \underline{\textcolor{green}{Cdaudio.SYS}},
    \underline{\textcolor{green}{Sfloppy.SYS}},
    \underline{\textcolor{green}{Flpydisk.SYS}},
    \underline{\textcolor{green}{Fdc.SYS}}
    },
ytick=data,
nodes near coords, 
nodes near coords align={horizontal},
scaled x ticks=false,
]
\addplot [fill=red!30,draw=red, postaction={pattern=north east lines}] coordinates {
    (13450,\underline{\textcolor{red}{mdd.sys}})
    (8168,\underline{\textcolor{red}{Beep.SYS$^4$}})
    (8168,\underline{\textcolor{red}{Beep.SYS$^3$}})
    (8168,\underline{\textcolor{red}{Beep.SYS$^2$}})
    (8167,\underline{\textcolor{red}{Beep.SYS$^1$}})
    (0,\underline{\textcolor{red}{imapi.sys}})
    (0,\underline{\textcolor{red}{processr.sys}})
    (0,\underline{\textcolor{red}{Cdaudio.SYS}})
    (0,\underline{\textcolor{red}{Sfloppy.SYS}})
    };
\addplot [fill=green!30,draw=green, postaction={pattern=north east lines}] coordinates {
    (20324,\underline{\textcolor{green}{kmixer.sys}})
    (20145,\underline{\textcolor{green}{drmkaud.sys}})
    (20142,\underline{\textcolor{green}{DMusic.sys}})
    (20141,\underline{\textcolor{green}{aec.sys}})
    (20139,\underline{\textcolor{green}{swmidi.sys}})
    (20132,\underline{\textcolor{green}{splitter.sys}})
    (19881,\underline{\textcolor{green}{Serial.SYS}})
    (19880,\underline{\textcolor{green}{Parport.SYS}})
    (9,\underline{\textcolor{green}{imapi.sys}})
    (9,\underline{\textcolor{green}{redbook.sys}})
    (8,\underline{\textcolor{green}{intelppm.sys}})
    (1,\underline{\textcolor{green}{Cdaudio.SYS}})
    (0,\underline{\textcolor{green}{Sfloppy.SYS}})
    (0,\underline{\textcolor{green}{Flpydisk.SYS}})
    (0,\underline{\textcolor{green}{Fdc.SYS}})
    };
\legend{Infected memory image, Baseline memory image}  
\end{axis}
\end{tikzpicture}
} % End of \scalebox
\caption{Timeline depicting unloaded kernel drivers (modules) from both memory images.}
\end{figure}
\end{document}

如果有人能帮助我就太好了。提前谢谢。

答案1

删除 ytick 线是故事的一部分,尽管您的条形图中确实发生了奇怪的事情……:

...
    \underline{\textcolor{green}{Sfloppy.SYS}},
    \underline{\textcolor{green}{Flpydisk.SYS}},
    \underline{\textcolor{green}{Fdc.SYS}}
    },
%ytick=data,            % <<<<<<<<
nodes near coords, 
nodes near coords align={horizontal},
scaled x ticks=false,
]
...

结果

请参阅这个简化版本,我尝试删除所有潜在的麻烦制造者...但仍然很奇怪。所以您的(符号)坐标可能不是这样工作的?

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

%\usetikzlibrary{decorations.pathreplacing,positioning, arrows.meta}
%\usetikzlibrary{patterns}


\begin{document}

 \begin{tikzpicture}
    \begin{axis}[ 
%       height=19.58cm,
%       width=15.44cm,
        xbar, 
%       xmin=-1000, xmax=25000,
%       xlabel={Time elapsed since the first kernel driver (module) was unloaded (in seconds)},
        symbolic y coords={
            mddsys,
            kmixersys,
            },
%       ytick=data,
        nodes near coords, 
        nodes near coords align={horizontal},
%       scaled x ticks=false,
    ]
    
    \addplot [fill=red!30,draw=red, 
    %postaction={pattern=north east lines}
    ] coordinates {
        (13450,mddsys)
        };
        
    \addplot [fill=green!30,draw=green, %postaction={pattern=north east lines}
    ] coordinates {
        (20324,kmixersys)
        };
        
    \legend{Infected memory image, Baseline memory image}  
    \end{axis}
 \end{tikzpicture}

\end{document}

减少

相关内容