Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Grégoire PETIT
DataScience
Commits
d11b0faa
Commit
d11b0faa
authored
Dec 06, 2018
by
Grégoire PETIT
Browse files
soldiers
parent
28bfed64
Changes
1
Hide whitespace changes
Inline
Side-by-side
Challenge3/code/importexportandplot.py
0 → 100644
View file @
d11b0faa
import
csv
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
matplotlib
as
mpl
def
exportgraphe
(
graphe
):
flat
=
[]
for
line
in
graphe
:
flat
+=
line
with
open
(
"D:/documents/IMT/datascience/challenge3/moodle/graphe.csv"
,
'a'
)
as
outcsv
:
#configure writer to write standard csv file
writer
=
csv
.
writer
(
outcsv
,
delimiter
=
','
,
quotechar
=
'|'
,
quoting
=
csv
.
QUOTE_MINIMAL
,
lineterminator
=
'
\n
'
)
for
item
in
flat
:
#Write item to outcsv
writer
.
writerow
([
item
[
0
],
item
[
1
],
item
[
2
][
0
],
item
[
2
][
1
],
item
[
2
][
2
],
item
[
2
][
3
],
item
[
2
][
4
],
item
[
2
][
5
],
item
[
2
][
6
],
item
[
2
][
7
],
item
[
2
][
8
],
item
[
2
][
9
],
item
[
2
][
10
],
item
[
2
][
11
],
item
[
2
][
12
],
item
[
2
][
13
],
item
[
2
][
14
]])
def
importgraphe
(
nbline
,
nbcol
):
with
open
(
"D:/documents/IMT/datascience/challenge3/moodle/graphe60jours.csv"
,
newline
=
''
)
as
f
:
reader
=
csv
.
reader
(
f
,
delimiter
=
','
)
uidlist
=
list
(
reader
)
res
=
[[[]
for
_
in
range
(
nbcol
)]
for
_
in
range
(
nbline
)]
compteur
=
0
for
line
in
uidlist
:
res
[
compteur
%
nbline
][
compteur
//
nbline
].
append
(
float
(
line
[
0
]))
res
[
compteur
%
nbline
][
compteur
//
nbline
].
append
(
float
(
line
[
1
]))
res
[
compteur
%
nbline
][
compteur
//
nbline
].
append
([
float
(
elt
)
for
elt
in
line
[
2
:]])
compteur
+=
1
return
(
res
)
nbline
,
nbcol
=
322
,
234
graphetest
=
importgraphe
(
nbline
,
nbcol
)[::
-
1
]
def
isZombie
(
case
):
res
=
1
if
case
[
0
]
==
0
:
res
=
0.5
if
sum
(
case
[
2
])
!=
0
:
res
=
0
return
(
res
)
x
=
[[
isZombie
(
case
)
for
case
in
line
]
for
line
in
graphetest
]
soldats
=
[[
231
,
139
],[
231
,
140
],[
231
,
141
],[
222
,
143
],[
221
,
143
],[
220
,
143
],[
219
,
143
],[
218
,
143
],[
217
,
143
],[
216
,
143
]]
for
point
in
soldats
:
x
[
321
-
point
[
0
]][
point
[
1
]]
=
0.8
fig
,
ax
=
plt
.
subplots
()
# define the colors
cmap
=
mpl
.
colors
.
ListedColormap
([
'b'
,
'g'
,
'c'
,
'm'
,
'y'
,
'k'
,
'w'
])
# create a normalize object the describes the limits of
# each color
bounds
=
[
0.
,
0.2
,
0.7
,
0.9
,
1.
]
norm
=
mpl
.
colors
.
BoundaryNorm
(
bounds
,
cmap
.
N
)
# plot it
ax
.
imshow
(
x
,
interpolation
=
'none'
,
cmap
=
cmap
,
norm
=
norm
)
plt
.
savefig
(
'D:/documents/IMT/datascience/challenge3/moodle/test.png'
)
plt
.
show
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment