I have a CSV file containing the following content:


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:

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

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

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.