我想绘制一个条形图,其中 x 轴标签为空,填充颜色反映图例中的轴标签。类似于此处的这个。
我的代码如下:
\documentclass[12pt, a4paper, titlepage]{scrartcl}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\graphicspath{{./Figures/}}
\usepackage{url}
%\usepackage{titlesec}
%\newcommand{\sectionbreak}{\clearpage}
\usepackage{dirtree}
\usepackage{color}
\usepackage{listings}
\usepackage{caption}
\usepackage{pdfpages}
\usepackage{pgfplots}
\newcommand{\courierword}[1]{\textsf{\itshape #1}}{\fontfamily{pcr}\selectfont}%
\setlength{\parindent}{0.0cm}
\setlength{\parskip}{1ex}
\setkomafont{sectioning}{\normalcolor\bfseries}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ylabel=Time(s),
]
\addplot[ybar]
coordinates{(Make Clean,14)};
\addplot[ybar]
coordinates{(Gradle Clean,16)};
\legend{Make Clean, Gradle Clean}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我不确定我是否理解您想要做什么:\documentclass[margin=5pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ylabel=Time(s),
ymin=0,
xtick=\empty,
enlarge x limits={abs=\pgfplotbarwidth/2},
ybar=-\pgfplotbarwidth,% ybar must be -bar width
x=\pgfplotbarwidth,
bar width=30pt,
legend style={
cells={anchor=west},
legend pos=outer north east,
}
]
%
\addplot coordinates{(1,14)};
\addplot coordinates{(2,16)};
%
\addplot coordinates{(4,10)};
\addplot coordinates{(5,6)};
%
\legend{Make Clean,Gradle Clean,Test 1,Test 2}
\end{axis}
\end{tikzpicture}
\end{document}
结果是