import math
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator as MNL
from matplotlib.colors import ListedColormap as LC
import pandas as pd
from pandas.api.types import CategoricalDtype
import seaborn as sns
#Get all pairs of numbers such that:
#1) Both the product and sum are at most 31.
#2) At least one of the product and sum are at most 12.
def get_date_pairs() :
texts = ["01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12"]
data = []
for a in texts[0:6]:
ai = int(a)
for b in texts[ai-1:12]:
bi = int(b)
pi = ai*bi
si = ai+bi
if ai == bi:
#One possibility for day/month.
k1 = 1
else :
#Two possibilities for day/month.
k1 = 2
if (pi <= 31 and si <= 31):
if (pi <= 12 or si <= 12):
#One possibility for day/month.
k2 = 1
if (pi <= 12 and si <= 12):
#Two possibilities for day/month.
k2 = 2
if pi == si:
#Unless they are both the same, pi = si = 4.
k2 = 1
p = str(pi)
if pi < 10 :
p = "0" + str(pi)
s = str(si)
if si < 10 :
s = "0" + str(si)
label = s + "/" + p
if pi < si :
label = p + "/" + s
datum = (b, a, b + "/" + a + " -->\n" + label, k1*k2)
data.append(datum)
return(data)
#Returns a dataframe of Number String A, Number String B, Label, and Group.
def get_data_df() :
#Get brood pairs.
data = get_date_pairs()
#Initiate lists.
num1 = []
num2 = []
label = []
group = []
for d in data :
num1.append(d[0])
num2.append(d[1])
label.append(d[2])
group.append(d[3])
df = pd.DataFrame(data = {"A": num1,
"B": num2,
"Label": label,
"Group": group})
return(df)
sns.set()
fig = plt.figure(figsize = (15, 9))
ax = fig.add_subplot()
cmap = LC(["#7AD151", "#2A788E", "#440154"])
df = get_data_df()
ns = ["1 Possibility",
"2 Possibilities",
"4 Possibilities"]
df['Group'] = df['Group'].astype(CategoricalDtype(categories = [1,2,4],
ordered = True))
scatter = plt.scatter(df["A"],
df["B"],
c = df['Group'].cat.codes,
cmap = cmap,
s = 0.01,
alpha = 1 )
for i in range(len(df)) :
x = int(df["A"][i])-1
y = int(df["B"][i])-1
c = ["",
"#7AD151",
"#2A788E",
"",
"#440154"][df["Group"][i]]
fill = plt.fill((x-0.45, x+0.45, x+0.45, x-0.45, x-0.45),
(y+0.15, y+0.15, y-0.15, y-0.15, y+0.15),
c = c,
ec = 'k',
alpha = 0.6)
plt.text(x,
y,
df["Label"][i],
ha = 'center',
va = 'center',
size = 13,
weight='bold')
#Title setup.
ax.set_title('Pairs of Dates', fontsize = 24)
#X-axis setup.
ax.set_xlabel('Number', fontsize = 22)
#Y-axis setup.
ax.set_ylabel('Number', fontsize = 22)
ax.tick_params(axis = 'both', which = 'major', labelsize = 18)
plt.legend(title = " Pair of Dates Possibilities",
title_fontsize = 20,
handles = scatter.legend_elements()[0],
labels = ns,
ncol = 1,
loc = "upper right",
fontsize = 18);
fig.savefig("2023.01.20 Express.png")
df
A | B | Label | Group | |
---|---|---|---|---|
0 | 01 | 01 | 01/01 -->\n01/02 | 2 |
1 | 02 | 01 | 02/01 -->\n02/03 | 4 |
2 | 03 | 01 | 03/01 -->\n03/04 | 4 |
3 | 04 | 01 | 04/01 -->\n04/05 | 4 |
4 | 05 | 01 | 05/01 -->\n05/06 | 4 |
5 | 06 | 01 | 06/01 -->\n06/07 | 4 |
6 | 07 | 01 | 07/01 -->\n07/08 | 4 |
7 | 08 | 01 | 08/01 -->\n08/09 | 4 |
8 | 09 | 01 | 09/01 -->\n09/10 | 4 |
9 | 10 | 01 | 10/01 -->\n10/11 | 4 |
10 | 11 | 01 | 11/01 -->\n11/12 | 4 |
11 | 12 | 01 | 12/01 -->\n12/13 | 2 |
12 | 02 | 02 | 02/02 -->\n04/04 | 1 |
13 | 03 | 02 | 03/02 -->\n05/06 | 4 |
14 | 04 | 02 | 04/02 -->\n06/08 | 4 |
15 | 05 | 02 | 05/02 -->\n07/10 | 4 |
16 | 06 | 02 | 06/02 -->\n08/12 | 4 |
17 | 07 | 02 | 07/02 -->\n09/14 | 2 |
18 | 08 | 02 | 08/02 -->\n10/16 | 2 |
19 | 09 | 02 | 09/02 -->\n11/18 | 2 |
20 | 10 | 02 | 10/02 -->\n12/20 | 2 |
21 | 03 | 03 | 03/03 -->\n06/09 | 2 |
22 | 04 | 03 | 04/03 -->\n07/12 | 4 |
23 | 05 | 03 | 05/03 -->\n08/15 | 2 |
24 | 06 | 03 | 06/03 -->\n09/18 | 2 |
25 | 07 | 03 | 07/03 -->\n10/21 | 2 |
26 | 08 | 03 | 08/03 -->\n11/24 | 2 |
27 | 09 | 03 | 09/03 -->\n12/27 | 2 |
28 | 04 | 04 | 04/04 -->\n08/16 | 1 |
29 | 05 | 04 | 05/04 -->\n09/20 | 2 |
30 | 06 | 04 | 06/04 -->\n10/24 | 2 |
31 | 07 | 04 | 07/04 -->\n11/28 | 2 |
32 | 05 | 05 | 05/05 -->\n10/25 | 1 |
33 | 06 | 05 | 06/05 -->\n11/30 | 2 |
df['Group'] = pd.to_numeric(df['Group'])
df['Group'].sum()
95