2017-05-18 36 views
0

我試圖使用.csv文件中的數據創建非數字標籤的條形圖。我已經瀏覽了一些較老的例子,但它們看起來很龐大笨重。我希望有更好的方法。這裏是我到目前爲止的MWE:LaTeX pgfplots使用字符串作爲條形圖標籤來自.csv

\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, 

回答

0

你使用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} 

enter image description here

相關問題