import pandas as pd
from matplotlib import pyplot as plt
plt.style.use('seaborn')
plt.rc('figure', figsize=(10, 8))
x = [5, 7, 8, 5, 6, 7, 9, 2, 3, 4, 4, 4, 2, 6, 3, 6, 8, 6, 4, 1]
y = [7, 4, 3, 9, 1, 3, 2, 5, 2, 4, 8, 7, 1, 6, 4, 9, 7, 7, 5, 1]
# s - size of dots
# c - color
# edgecolor - edges to the circles
# cmap - color map => https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html
# plt.scatter(x, y, s=100, c='green', marker='x')
# plt.scatter(x, y, s=100, c='red', edgecolor='black',
# linewidth=1, alpha=0.75)
# color and size on a per mark basis
colors = [7, 5, 9, 7, 5, 7, 2, 5, 3, 7, 1, 2, 8, 1, 9, 2, 5, 6, 7, 5]
sizes = [209, 486, 381, 255, 191, 315, 185, 228, 174,
538, 239, 394, 399, 153, 273, 293, 436, 501, 397, 539]
plt.scatter(x, y, s=sizes, c=colors, cmap='Reds', edgecolor='black',
linewidth=1, alpha=0.75)
cbar = plt.colorbar()
cbar.set_label('Satisfaction level')
plt.tight_layout()
plt.show()
# EXAMPLE
data = pd.read_csv(r'examples/2019-05-31-data.csv')
data.head()
view_count | likes | ratio | |
---|---|---|---|
0 | 8036001 | 324742 | 96.91 |
1 | 9378067 | 562589 | 98.19 |
2 | 2182066 | 273650 | 99.38 |
3 | 6525864 | 94698 | 96.25 |
4 | 9481284 | 582481 | 97.22 |
view_count = data['view_count']
likes = data['likes']
ratio = data['ratio']
plt.scatter(view_count, likes, edgecolor='black', c=ratio,
cmap='summer', linewidth=1, alpha=0.75)
cbar = plt.colorbar()
cbar.set_label('Like Dislike Ratio')
plt.xscale('log')
plt.yscale('log')
plt.title('Trending YouTube Videos')
plt.xlabel('View Count')
plt.ylabel('Total Likes')
plt.tight_layout()
plt.show()