Search code examples
pythonbar-chartdata-visualizationpython-ggplot

categorical x data on bar charts python ggplot


The picture illustrates the problem - can you get rid of these extra 'foo' and 'bar' ticks on the x-axis?

Problematic x-axis


Solution

  • I found my answer here: http://www.cookbook-r.com/Graphs/Bar_and_line_graphs_(ggplot2)/

    Most importantly, the working code specifies stat='identity'.

    df = pandas.DataFrame({"x" : ["foo", "bar"], "y": [2000,1500]})
    plot = ggplot(aes(x="x",y="y"), data=df) +\ # y NOT weight
             geom_bar(stat='identity') +\ # stat='bin' by default
    print plot