如何使用 TiKz 绘制以下性能图表?

如何使用 TiKz 绘制以下性能图表?

我想将一些百分比绘制成线条。因此我尝试了以下方法:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[legend style={at={(.9,0.9),anchor=north east}},
symbolic x coords={Accuracy, score, recall, precision, hamming loss, jaccard similarity, F-beta score}, xtick=data]

\addplot[mark=diamond*,thick,red] coordinates {
(Accuracy,12.90129) (score,34.908839) (recall,60.29032309) (precision,22.09321093) (hamming loss,50.3093) (jaccard similarity,90.2323) (F-beta score,89.1920129)
};

\addlegendentry{data set 1}
\addplot[mark=o,mark options={solid},blue,thick,dashed] coordinates {
(Accuracy,32.90129) (score,14.908839) (recall,10.29032309) (precision,26.09321093) (hamming loss,40.3093) (jaccard similarity,90.2323) (F-beta score,39.1920129)
};
\addlegendentry{data set 2}
\end{axis}
\end{tikzpicture}
\end{document}

我该如何解决这个问题才能看到线图类型?

答案1

从你的问题中很难理解你想做什么,但看看你的图,我认为你只是想移动图例框:这可以使用legend style。此外,轴上的标签会相互碰撞,因此你可能想要使用x tick label style来旋转它们。所有这些都在pgfplots 手册

有了这些,你的图表就变成了:

在此处输入图片描述

完整代码如下:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[legend style={at={(.9,0.9),anchor=north east}},
             symbolic x coords={Accuracy, score, recall, precision, hamming loss,
             jaccard similarity, F-beta score}, xtick=data,
             x tick label style={rotate=45,anchor=east},
             legend style={cells={anchor=east}, legend pos=outer north east,}
]

\addplot[mark=diamond*,thick,red] coordinates {
    (Accuracy,12.90129)
    (score,34.908839)
    (recall,60.29032309)
    (precision,22.09321093)
    (hamming loss,50.3093)
    (jaccard similarity,90.2323)
    (F-beta score,89.1920129)
};

\addlegendentry{data set 1}
\addplot[mark=o,mark options={solid},blue,thick,dashed] coordinates {
    (Accuracy,32.90129)
    (score,14.908839)
    (recall,10.29032309)
    (precision,26.09321093)
    (hamming loss,40.3093)
    (jaccard similarity,90.2323)
    (F-beta score,39.1920129)
};
\addlegendentry{data set 2}
\end{axis}
\end{tikzpicture}
\end{document}

顺便说一句,我发现你的代码真的很难阅读:如果你添加一点空间和规律,我想很容易看出发生了什么。

相关内容