How can I label or tick in pandas for my data sets?

Viewed 71

Below is my data-set, I am unable to tick or label [City 1, City 2, City 3 & City 4] in x-axis for the bar graph. Its a 1*4 matrix.

City1    City2    City3    City4
1000     1020     940      720

Here is my code,

df.plot.bar(color = 'deepbluesky', width = 2)
plt.xticks([], rotation = 'vertical')

A help would be appreciated, thank you!

2 Answers

Lets try make the Cities and corresponding values appear in columns by stacking. Then set Cities as index. The index is by default forced to plot on the x axis.

Edited as suggested by @Trenton McKinney

df.T.plot.bar()

enter image description here

Let's say my dataset

Dataset

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('Position_Salaries.csv')
x = df["Position"]
y = df["Salary"]
plt.figure(figsize=(15,8))
plt.title("Position vs Salary")
plt.bar(x,y)
plt.xlabel("Positions")
plt.ylabel("Salary")
plt.show()

plot

Related