import math
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import StrMethodFormatter as SMF
import pandas as pd
import seaborn as sns
#Create Data
data = pd.DataFrame(columns = ['Units',
'Tens',
'Freq'])
for t in range(0,10) :
for u in range(0,10) :
data = data.append({'Units' : u,
'Tens' : t,
'Freq' : 0},
ignore_index = True)
for i in range(0,100) :
v = ((i**2 + i) / 2) % 100
data.at[v, 'Freq'] += 1
data
Units | Tens | Freq | |
---|---|---|---|
0 | 0 | 0 | 2 |
1 | 1 | 0 | 2 |
2 | 2 | 0 | 0 |
3 | 3 | 0 | 5 |
4 | 4 | 0 | 0 |
... | ... | ... | ... |
95 | 5 | 9 | 2 |
96 | 6 | 9 | 2 |
97 | 7 | 9 | 0 |
98 | 8 | 9 | 0 |
99 | 9 | 9 | 0 |
100 rows × 3 columns
sns.set()
fig = plt.figure(figsize = (12.15, 10))
ax = fig.add_subplot(xlim = (-0.5, 9.5),
ylim = (-0.5, 9.5))
heatmap = plt.scatter(x = data['Units'],
y = data['Tens'],
c = data['Freq'],
cmap = 'YlGn',
marker = "s",
s = 2850)
#Title setup.
ax.set_title('Distribution of Last Two Digits of Triangular Numbers', fontsize = 24)
#X-axis setup.
ax.set_xlabel('Units Digit', fontsize = 22)
ax.set_xticks(range(0,10))
#Y-axis setup.
ax.set_ylabel('Tens Digit', fontsize = 22)
ax.set_yticks(range(0,10))
ax.tick_params(axis = 'both', which = 'major', labelsize = 18)
common = [('03', 3, 0),
('28', 8, 2),
('53', 3, 5),
('78', 8, 7)]
for c in common:
plt.annotate(c[0],
(c[1], c[2]),
c = "w",
fontsize = 28,
ha = "center",
va = "center")
#Colorbar.
plt.colorbar(heatmap).set_label('# of Occurences \n Every 100', fontsize = 22);
fig.savefig("2023.03.03 Express.png",
bbox_inches = 'tight')