plt_tutorial
plt_tutorial
import csv
import numpy as np
import pandas as pd
from collections import Counter
Line Plot
In [2]: ages_x = [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55]
py_dev_y = [20046, 17100, 20000, 24744, 30500, 37732, 41247, 45372, 48876, 53850, 57287, 63016, 65998, 70003,
70000, 71496, 75370, 83640, 84666, 84392, 78254, 85000, 87038, 91991, 100000, 94796, 97962, 93302,
99240, 102736, 112285, 100771, 104708, 108423, 101407, 112542, 122870, 120000]
[<matplotlib.lines.Line2D at 0x1c126c46c40>]
Out[2]:
In [3]: js_dev_y = [16446, 16791, 18942, 21780, 25704, 29000, 34372, 37810, 43515, 46823, 49293, 53437,
56373, 62375, 66674, 68745, 68746, 74583, 79000, 78508, 79996, 80403, 83820, 88833,
91660, 87892, 96243, 90000, 99313, 91660, 102264, 100000, 100000, 91660, 99240, 108000,
105000, 104000]
plt.plot(ages_x, js_dev_y, label='JavaScript')
[<matplotlib.lines.Line2D at 0x1c1273eefa0>]
Out[3]:
In [4]: dev_y = [17784, 16500, 18012, 20628, 25206, 30252, 34368, 38496, 42000, 46752, 49320, 53200, 56000, 62316,
64928, 67317, 68748, 73752, 77232, 78000, 78508, 79536, 82488, 88935, 90000, 90056, 95000, 90000,
91633, 91660, 98150, 98964, 100000, 98988, 100000, 108923, 105000, 103117]
plt.plot(ages_x, dev_y, color='#444444', linestyle='--', label='All Devs')
[<matplotlib.lines.Line2D at 0x1c12746c460>]
Out[4]:
Bar Chart
In [5]: plt.style.use("fivethirtyeight")
data = pd.read_csv('data.csv')
ids = data['Responder_id']
lang_responses = data['LanguagesWorkedWith']
language_counter = Counter()
languages = []
popularity = []
languages.reverse()
popularity.reverse()
plt.barh(languages, popularity)
plt.tight_layout()
plt.show()
Pie Charts
In [6]: from matplotlib import pyplot as plt
plt.style.use("fivethirtyeight")
Stack Plots
In [7]: plt.style.use("fivethirtyeight")
minutes = [1, 2, 3, 4, 5, 6, 7, 8, 9]
player1 = [8, 6, 5, 5, 4, 2, 1, 1, 0]
player2 = [0, 1, 2, 2, 2, 4, 4, 4, 4]
player3 = [0, 1, 1, 1, 2, 2, 3, 3, 4]
plt.legend(loc=(0.07, 0.05))
Fill Between
In [8]: data = pd.read_csv('data2.csv')
ages = data['Age']
dev_salaries = data['All_Devs']
py_salaries = data['Python']
js_salaries = data['JavaScript']
overall_median = 57287
plt.legend()
plt.tight_layout()
plt.show()
Scatter Plots
In [9]: plt.style.use('seaborn')
data = pd.read_csv('2019-05-31-data.csv')
view_count = data['view_count']
likes = data['likes']
ratio = data['ratio']
cbar = plt.colorbar()
cbar.set_label('Like/Dislike Ratio')
plt.xscale('log')
plt.yscale('log')
plt.tight_layout()
plt.show()
In [ ]: