application_vnd.jupyter.stderr_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

college_categories = ['IIM A', 'IIM B', 'IIM C', 'IIM L', 'IIM I', 'IIM K']
time_periods = [2019, 2020, 2021, 2022]
avg_sal_data = np.array([[12, 10, 12, 13], [11, 9, 10, 12], [11, 8, 9, 10], [10, 7, 8, 9], [9, 8, 7, 8], [8, 7, 8, 9]])

ranks = np.argsort(avg_sal_data, axis=0)[::-1]
rank_data = np.zeros_like(avg_sal_data)
for i in range(len(time_periods)):
    rank_data[:, i] = ranks[:, i] + 1
rank_data

df = pd.DataFrame(6 - rank_data.T, columns=[str(i) for i in college_categories])
df['Time'] = time_periods

fig, ax = plt.subplots()
fig = df.plot(x='Time', kind='bar', stacked=False, ax=ax)
ax.set_xlabel('Year', fontsize=15, fontweight='bold')
ax.set_ylabel('Rank', fontsize=15, fontweight='bold')
ax.set_title('Bar Chart', fontsize=20, fontweight='bold')
ax.set_xticklabels(df.Time, rotation=0)
ax.set_yticklabels(['', 6, 5, 4, 3, 2, 1])
plt.show()