Ein Balkendiagramm mit einer ordinalen X-Achse erstellen?

Ein Balkendiagramm mit einer ordinalen X-Achse erstellen?

Ich versuche, ein Balkendiagramm zu erstellen, bei dem die Werte entlang der x-Achse nicht relevant sind. Mein aktueller Code lautet:

\documentclass{article}
\beging{document}
\begin{figure}
\centering
     \begin{tikzpicture}
        \begin{axis}[ylabel=Similarity,
                    ybar]
            \addplot table[y=Pref, col sep=comma] {5_Results/evalresults.csv};
            \addplot table[y=Rec, col sep=comma] {5_Results/evalresults.csv};

        \end{axis}
    \end{tikzpicture}
    \caption{A bar chart of user and course similarity}
    \label{evalresultsbar}
\end{figure}
\end{document}

Dadurch wird jedoch dieses Diagramm erstellt. Ich möchte nicht nur die Werte entlang der X-Achse entfernen, sondern auch verhindern, dass die Balken übereinander gestapelt werden.

Die von mir gewünschte Ausgabe würde ungefähr so ​​aussehen wie dieses von Google Sheets generierte Diagramm: Bildbeschreibung hier eingeben

Der Inhalt von evalresults.csv

Pref,Rec,label
0.00,14.29,a
0.00,16.67,a
0.00,16.67,a
0.00,20.00,a
0.00,20.00,a
0.00,25.00,a
0.00,33.33,a
0.00,33.33,a
0.00,33.33,a
0.00,50.00,a
0.00,50.00,a
0.00,50.00,a
0.00,50.00,a
0.00,50.00,a
0.00,60.00,a
0.00,60.00,a
0.00,60.00,a
33.33,25.00,a
33.33,25.00,a
33.33,33.33,a
33.33,33.33,a
33.33,60.00,a
33.33,60.00,a
33.33,66.67,a
33.33,75.00,a
33.33,75.00,a
33.33,75.00,a
33.33,80.00,a
33.33,80.00,a
33.33,100.00,a
66.67,75.00,a
66.67,80.00,a
66.67,100.00,a
66.67,100.00,a
66.67,100.00,a
66.67,100.00,a
100.00,100.00,a

Antwort1

Sie müssen die X-Koordinate irgendwie angeben, fügen Sie also x expr=\coordindexdie Optionen für hinzu table, wie unten gezeigt.

Ich habe dem Code einige Kommentare hinzugefügt

Bildbeschreibung hier eingeben

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{pgfplotstable} % for pgfplotstableread, but you can use the filename in the \addplot as you did instead
\pgfplotstableread[col sep=comma]{
Pref,Rec,label
0.00,14.29,a
0.00,16.67,a
0.00,16.67,a
0.00,20.00,a
0.00,20.00,a
0.00,25.00,a
0.00,33.33,a
0.00,33.33,a
0.00,33.33,a
0.00,50.00,a
0.00,50.00,a
0.00,50.00,a
0.00,50.00,a
0.00,50.00,a
0.00,60.00,a
0.00,60.00,a
0.00,60.00,a
33.33,25.00,a
33.33,25.00,a
33.33,33.33,a
33.33,33.33,a
33.33,60.00,a
33.33,60.00,a
33.33,66.67,a
33.33,75.00,a
33.33,75.00,a
33.33,75.00,a
33.33,80.00,a
33.33,80.00,a
33.33,100.00,a
66.67,75.00,a
66.67,80.00,a
66.67,100.00,a
66.67,100.00,a
66.67,100.00,a
66.67,100.00,a
100.00,100.00,a
}\data
\begin{document}    
\begin{tikzpicture}
\begin{axis}[
  ylabel=Similarity,
  ybar,
  % reduce bar width
  bar width=1pt,
  % to remove whitespace below bars
  ymin=0,
  % only want the x-axis on the bottom
  axis x line=bottom,
  % add some horizontal space between bars and axis limits
  enlarge x limits=0.05,
  % don't draw the ticks
  tick style={draw=none},
  % remove x ticks
  xtick=\empty,
  % enable grid
  grid=major,
  % don't draw the vertical lines for the y-axes
  every outer y axis line/.style={draw=none},
  %position legend outside the axis, top right
  legend pos=outer north east,
  % don't draw box around legend
  legend style={draw=none}
]
    \addplot [fill=red!50,draw=none] table[x expr=\coordindex,y=Pref, col sep=comma] {\data};
    \addplot [fill=blue!30,draw=none] table[x expr=\coordindex,y=Rec, col sep=comma] {\data};

   \addlegendentry{Pref}
   \addlegendentry{Rec}

\end{axis}
\end{tikzpicture}
\end{document}

verwandte Informationen