test.py 1.72 KB
#Vertices+Conselhos
 
file = open('ValeSousaVert.txt')

nlin = -1
vert4MU = {}
conc4MU = {}

MUNames = []
MU4conc = {'Paiva':[], 'Penafiel':[], 'Paredes':[]}

xmin =  100000000000
xmax = -100000000000
ymin =  100000000000
ymax = -100000000000

for line in file:
	nlin += 1
	if nlin == 0:
		continue
	lex = line.split()

	if nlin < 5 or nlin > 54405:
		print(lex)

	if lex[0] not in vert4MU:
		vert4MU[lex[0]] = []
		conc4MU[lex[0]] = lex[4]
		MUNames.append(lex[0])

	x = float(lex[2])
	y = float(lex[3])
	vert4MU[lex[0]].append((x,y))

	if xmin > x : xmin = x
	if xmax < x : xmax = x
	if ymin > y : ymin = y
	if ymax < y :
		ymax = y
		nymax = lex[0]

	MU4conc[lex[4]].append(lex[0])

file.close()

print(len(vert4MU))
print(MUNames[0],MUNames[-1])

print(len(MU4conc),'=', len(MU4conc['Paiva']), len(MU4conc['Penafiel']), len(MU4conc['Paredes']))

# num = '1626',
# print(MUconc[num])
# print(MUvert[num])

#%matplotlib notebook

import matplotlib.pyplot as plt

Cores = {'Paiva':'fuchsia', 'Penafiel':'lime', 'Paredes':'royalblue', 'No':'gray'}

fig = plt.figure(figsize=(8,10))
ax = plt.gca()
ax.set_facecolor('lightgray')

for unit in MUNames: 
	xx = []
	yy = []
	for v in vert4MU[unit]:
		xx.append(v[0])
		yy.append(v[1])
	conc = conc4MU[unit]
	clr = Cores.get(conc,'No')
	plt.fill(xx, yy, facecolor=clr, edgecolor='black', linewidth=1)

plt.plot([-25000, -25010], [165000, 165010], lw=15, c=Cores['Paredes'],   label='Paredes')
plt.plot([-25000, -25010], [165000, 165010], lw=15, c=Cores['Penafiel'],  label='Penafiel')
plt.plot([-25000, -25010], [165000, 165010], lw=15, c=Cores['Paiva'],     label='Paiva')
plt.plot([-25000, -25010], [165000, 165010], lw=17, c='lightgray')

plt.legend()
plt.tight_layout()

#plt.savefig('VSousa22',dpi=100)
plt.show()