Renaming the x-axis values in matplotlib

4k views Asked by At

NOTE: This is all done on a windows 7 x64bit machine running python2.7 and the most recent version of matplotlib.

I have a csv file that contains the liquor sales in Iowa from January 2014 to February 2015. If your interest is suddenly piqued, the file can be found at: https://data.iowa.gov/Economy/Iowa-Liquor-Sales/m3tr-qhgy

I have sorted the data so that now I have a csv file with two columns, named 'Brands' and 'Number Sold'. The Brands column has the list of unique liquors from the original file. The Number Sold column has how many of each liquor were sold in the 1+ year. I am now trying to graph this data using matplotlib.

My code looks like this:

1    import pandas as pd
2    import matplotlib.pyplot as plt
3
4    a = pd.read_csv('sorted_sales.csv', header=0)
5
6    my_plot = a[0:].sort(columns='Number Sold', ascending=True).plot(kind='bar', legend=None)
7    my_plot.set_xlabel('Brands')
8    my_plot.set_ylabel('Number Sold')
9
10    plt.show()

This outputs a bar graph that has the y-axis as the number of bottles sold, and the x-axis is the index of each liquor. My problem is that I want the labels along the x-axis to be the names of each liquor not the index of each liquor. I have tried playing with the xtick option, but I can't get it to work correctly.

Sorry if this is not clear enough. I am not sure how else to word it.

1

There are 1 answers

3
Andreus On BEST ANSWER

You are looking for set_xticklabels