In [1]:
#Making Bar charts using matplotlib
In [2]:
from matplotlib import pyplot as plt
In [4]:
plt.style.use("fivethirtyeight")

ages_x = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]

dev_y = [38496, 42000, 46752, 49320, 53200,
         56000, 62316, 64928, 67317, 68748, 73752]

py_dev_y = [45372, 48876, 53850, 57287, 63016,
            65998, 70003, 70000, 71496, 75370, 83640]

js_dev_y = [37810, 43515, 46823, 49293, 53437,
            56373, 62375, 66674, 68745, 68746, 74583]
In [6]:
plt.plot(ages_x, dev_y, color="#444444", label="All Devs")
plt.plot(ages_x, py_dev_y, color="#008fd5", label="Python")
plt.plot(ages_x, js_dev_y, color="#e5ae38", label="JavaScript")


plt.legend()

plt.title("Median Salary (USD) by Age")
plt.xlabel("Ages")
plt.ylabel("Median Salary (USD)")

plt.tight_layout()
plt.show()
In [7]:
import numpy as np
In [9]:
ages_x = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]

x_indexes = np.arange(len(ages_x))
print(x_indexes)
[ 0  1  2  3  4  5  6  7  8  9 10]
In [11]:
width=0.25

plt.bar(x_indexes -width, dev_y, width=width, color="#444444", label="All Devs")
plt.bar(x_indexes, py_dev_y, width=width, color="#008fd5", label="Python")
plt.bar(x_indexes + width, js_dev_y, width=width, color="#e5ae38", label="JavaScript")


plt.legend()

plt.title("Median Salary (USD) by Age")
plt.xlabel("Ages")
plt.ylabel("Median Salary (USD)")

plt.tight_layout()
plt.show()
In [12]:
#correcting x axis so instead of offset, ages will be showned

plt.bar(x_indexes -width, dev_y, width=width, color="#444444", label="All Devs")
plt.bar(x_indexes, py_dev_y, width=width, color="#008fd5", label="Python")
plt.bar(x_indexes + width, js_dev_y, width=width, color="#e5ae38", label="JavaScript")


plt.legend()

#for correcting x-axis
plt.xticks(ticks=x_indexes, labels=ages_x)

plt.title("Median Salary (USD) by Age")
plt.xlabel("Ages")
plt.ylabel("Median Salary (USD)")

plt.tight_layout()
plt.show()