0

我正在尝试使用 .csv 文件中的数据来创建带有非数字标签的条形图。我浏览了一些较旧的示例,但它们看起来又大又笨重。我希望有更好的方法。到目前为止,这是我作为 MWE 所拥有的:

\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=x axis label,ylabel=y axis label]
\addplot [ybar] table [symbolic x coords=Month, y=Dozers, col sep=comma] {cnrldata.csv};
\end{axis}
\end{tikzpicture} \\
\end{document}

从这里我当然得到错误:

Package PGF Math Error: Could not parse input 'May 14' as a floating point number, sorry. The unreadable part was near 'May 14'.. ... y=Dozers, col sep=comma] {data.csv};

表中的数据如下所示:

Month, Dozers,
January, 0.85,
February, 0.7,
4

1 回答 1

0

你的用法symbolic x coords是错误的。阅读手册

提示: 您更有可能在TeX.SX上得到此类问题的回答。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xlabel={$x$ axis label},
    ylabel={$y$ axis label},
    symbolic x coords={January,February,March,April,May},
    ]
    \addplot [ybar] table [x=Month, y=Dozers, col sep=comma] {
      Month, Dozers
      January, 0.85
      February, 0.7
      March,    0.6
      April,    0.9
      May,      0.4
    };
  \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图像描述

于 2017-05-28T23:52:10.963 回答