I have the following dataframe which produces the following plot:
JavaScript
x
4
1
df = pd.DataFrame({'column_name':[4,4,4,4,4,4,4,4,2,2,2,3,3,5]})
2
df['column_name'].value_counts().plot(kind='bar')
3
plt.show()
4
How can I change the x-axis values from 4, 2, 3, 5 to Gen Y, Gen X, Gen Z, and Greatest, respectively. Here is my desired output:
Advertisement
Answer
You can use plt.xticks() to replace the x value for each column like below:
JavaScript
1
3
1
df['column_name'].value_counts().plot(kind='bar')
2
plt.xticks([0,1,2,3],['Gen Y', 'Gen X', 'Gen Z', 'Greatest'])
3