【问题标题】:LaTeX pgfplots use strings for barchart label from .csvLaTeX pgfplots 使用来自 .csv 的条形图标签的字符串
【发布时间】:2017-05-18 16:03:06
【问题描述】:

我正在尝试使用 .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,

【问题讨论】:

    标签: latex pgf


    【解决方案1】:

    您对symbolic x coords 的使用是错误的。阅读manual

    提示:您更有可能在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}
    

    【讨论】:

      猜你喜欢
      • 2013-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-22
      • 1970-01-01
      • 1970-01-01
      • 2022-10-16
      • 1970-01-01
      相关资源
      最近更新 更多