-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgermany_plot_v04.py
184 lines (165 loc) · 7.11 KB
/
germany_plot_v04.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#! /usr/bin/python3
import pandas as pd
import geopandas
import matplotlib.pyplot as plt
import numpy as np
import pathlib
p = pathlib.Path("output/")
p.mkdir(parents=True, exist_ok=True)
# output file names
# output="germany_workshops_annotated_rdm_chemotion.png"
output="germany_workshops_annotated_rdm_done.png"
# output="germany_workshops_annotated_chemotion.png"
outputlegend="legend_%s"%(output)
output = "output/" + output
outputlegend = "output/" + outputlegend
# change font
plt.rcParams["font.family"] = "sans-serif"
plt.rcParams["mathtext.fontset"] = "dejavusans"
plt.rcParams['mathtext.rm'] = 'dejavusans'
plt.rcParams['mathtext.it'] = 'dejavusans:italic'
plt.rcParams['mathtext.bf'] = 'dejavusans:bold'
params = {'text.usetex': False, 'mathtext.fontset': 'dejavusans'}
plt.rcParams.update(params)
#colors
#nfdi4chemblack25 = (0/255, 0/255, 0/255, 0.25)
nfdi4chemblack25 = (191/255, 191/255, 191/255)
nfdi4chempetrol = (0/255, 156/255, 188/255)
nfdi4chemorange = (238/255, 166/255, 0/255)
nfdi4chemyellow = (241/255, 222/255, 30/255)
nfdi4chemviolett = (149/255, 86/255, 158/255)
nfdi4chemred = (227/255, 6/255, 19/255)
# to separat legend and figure, a while loop starts here (not the most elegant way to do it but it works)
m = 0
while m <2 :
#load map of europe and chose right NUTS Level, source Eurostat NUTS 2021
#(https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts)
df = geopandas.read_file("NUTS_RG_20M_2021_4326/NUTS_RG_20M_2021_4326.shp")
# use if you want germany without borders
# mapdf = df[df["NAME_LATN"]=="Deutschland"]
# use if you want germany with borders
tmpdf = df[df["CNTR_CODE"]=="DE"]
mapdf = tmpdf[df["LEVL_CODE"]==1]
#load information from location.dat
city, long, lat, status, topic, kind = np.loadtxt("location_rdm.dat", unpack=True, dtype='str')
# city, long, lat, status, topic, kind = np.loadtxt("location_chemotion.dat", unpack=True, dtype='str')
# city, long, lat, status, topic, kind = np.loadtxt("location.dat", unpack=True, dtype='str')
#define figure
fig=plt.figure(figsize=(4,4), dpi=300)
ax=fig.add_subplot(111)
#plot map
#mapdf.plot(ax=ax, color=nfdi4chempetrol, edgecolor="white", linewidth=0.1)
# mapdf.plot(ax=ax, color=nfdi4chemblack25, edgecolor=nfdi4chemblack25, linewidth=0.5) #style 01
# mapdf.plot(ax=ax, color=nfdi4chemblack25, edgecolor="black", linewidth=0.5) #style 02, borerstlye 01
mapdf.plot(ax=ax, color=nfdi4chemblack25, edgecolor="white", linewidth=0.5) #borderstlye 02
# mapdf.plot(ax=ax, color=nfdi4chemblack25, edgecolor="black", linewidth=0.2) #style 03
n=0
citychecklist = []
labelcheck = [0, 0, 0, 0]
while n<len(city):
topiclabel = None
if m == 1:
ms = 35
elif city[n]=="8xNationalChemotion" or city[n]=="8xNationalRDM":
ms = 0
else:
ms = 20
#plot locations dependend of status and topic, kind is not taken into account
if topic[n] =='RDM' and status[n]=='done':
markersymbol = 'o'
if status[n] =='done':
colordata = nfdi4chempetrol
if labelcheck[0] == 0:
topiclabel = 'RDM (past)'
labelcheck[0] = 1
else:
colordata = nfdi4chemorange
if labelcheck[1] == 0:
topiclabel = 'RDM (planned)'
labelcheck[1] = 1
elif topic[n] =='Chemotion':
markersymbol = 's'
if status[n] =='done':
colordata = nfdi4chempetrol
if labelcheck[2] == 0:
topiclabel = 'Chemotion ELN (past)'
labelcheck[2] = 1
else:
colordata = nfdi4chemorange
if labelcheck[3] == 0:
topiclabel = 'Chemotion ELN (planned)'
labelcheck[3] = 1
#avoid distortion of the plot by treating the coordinates right
# change markersize when multiple events are at the same location
if city[n] in citychecklist:
if citychecklist.count(city[n]) ==1:
latfloat=float(lat[n])-0.3
coordinates = {"latitude": [long[n]], "longitude": [latfloat]}
if citychecklist.count(city[n]) ==2:
longfloat=float(long[n])+0.19
coordinates = {"latitude": [longfloat], "longitude": [lat[n]]}
if citychecklist.count(city[n]) ==3:
longfloat=float(long[n])+0.19
latfloat=float(lat[n])-0.3
coordinates = {"latitude": [longfloat], "longitude": [latfloat]}
dftest = pd.DataFrame(coordinates)
else:
# ms = standardms
coordinates = {"latitude": [long[n]], "longitude": [lat[n]]}
dftest = pd.DataFrame(coordinates)
if topic[n] =='RDM' and status[n]=='done':
markersymbol = 'o'
if status[n] =='done':
colordata = nfdi4chempetrol
# if labelcheck[0] == 0:
# topiclabel = 'RDM (past)'
# labelcheck[0] = 1
else:
colordata = nfdi4chemorange
# if labelcheck[1] == 0:
# topiclabel = 'RDM (planned)'
# labelcheck[1] = 1
locations = geopandas.GeoDataFrame(coordinates, geometry=geopandas.points_from_xy(dftest.longitude, dftest.latitude),crs = "EPSG:4326")
# locations.plot(ax=ax, marker=markersymbol, markersize=ms, color=colordata, label=topiclabel, linestyle='None') #style 01, style 02 borderstyle 01
locations.plot(ax=ax, marker=markersymbol, markersize=ms, color=colordata, label=topiclabel, linestyle='None', edgecolor="black", linewidth=0.2) #style 03
# add location name to point
if not city[n] in citychecklist:
x = locations.geometry.x
y = locations.geometry.y
if city[n]=="Aachen":
plt.annotate(city[n], xy=(x,y), xytext=(0,-7.0), textcoords="offset points", ha="center", size="5")
elif city[n]=="Bochum":
plt.annotate(city[n], xy=(x,y), xytext=(-4.0,-2.0), textcoords="offset points", ha="right", size="5")
elif city[n]=="Mainz" or city[n]=="Dresden":
plt.annotate(city[n], xy=(x,y), xytext=(-4.0,-7.0), textcoords="offset points", ha="center", size="5")
elif city[n]=="Potsdam":
plt.annotate(city[n], xy=(x,y), xytext=(4.0,-4.0), textcoords="offset points", size="5")
#elif city[n]=="Hannover" or city[n]=="Halle" or city[n]=="Münster":
elif city[n]=="Hannover" or city[n]=="Halle":
plt.annotate(city[n], xy=(x,y), xytext=(0,4.0), textcoords="offset points", ha="center", size="5")
elif city[n]=="Darmstadt":
plt.annotate(city[n], xy=(x,y), xytext=(0,-6.0), textcoords="offset points", ha="center", size="5")
elif city[n]=="8xNationalChemotion":
plt.annotate("+ 9 national Chemotion WS", xy=(x,y), xytext=(0.0,-2.0), textcoords="offset points", size="5")
elif city[n]=="national":
plt.annotate("8x national", xy=(x,y), xytext=(4.0,-2.0), textcoords="offset points", size="5")
elif city[n]=="international":
plt.annotate("2x international", xy=(x,y), xytext=(4.0,-2.0), textcoords="offset points", size="5")
else:
plt.annotate(city[n], xy=(x,y), xytext=(4.0,-2.0), textcoords="offset points", size="5")
#for x, y, label in zip(cities.geometry.x, cities.geometry.y, cities.name):
# ax.annotate(label, xy=(x, y), xytext=(3, 3), textcoords="offset points")
citychecklist.append(city[n])
n += 1
if m==0:
plt.axis([5,15.2,47,55])
plt.title(" ")
plt.axis('off')
plt.savefig(output, bbox_inches='tight', pad_inches=0.05, transparent=True)
else:
plt.legend(loc="lower left", numpoints=1, frameon=False)
plt.axis([4,15,44,46])
plt.axis('off')
plt.savefig(outputlegend, bbox_inches='tight', pad_inches=0.05, transparent=True)
plt.clf()
m += 1