0

I have a CSV file containing the following content:

optimization,time
a,10
b,20
c,5

From that file, I would like to create a bar plot, with one bar for each optimization on the x-axis with the time on the y-axis.

So far, I was able to generate the following plot:

bar plot draft

using the following code:

\begin{figure}
 \pgfplotstableread[col sep=comma]{data.csv}\datatable

 \begin{tikzpicture}
    \begin{axis}[
        ybar,
        ymin = 0,
        xtick = data,
        xticklabels from table={\datatable}{optimization},
        ylabel={Running Time}
    ]
    \addplot table [x expr=\coordindex, y={time}]{\datatable};
    \end{axis}
 \end{tikzpicture}
 
\end{figure}

However, I'd like each bar to have a different color and a legend containing an entry for each optimization (instead of labeled below the axis). The most feasible approach to achieve this seems to be to use multiple \addplot statements, one for each optimization. However, this is cumbersome with an increasing number of optimizations to plot.

What would be a good way to achieve this? I'm free to change the structure of the CSV file, if that helps.

0