Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
geopyck
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alice Brenon
geopyck
Commits
98bb5f9f
Commit
98bb5f9f
authored
1 year ago
by
Alice Brenon
Browse files
Options
Downloads
Patches
Plain Diff
Add a script to draw graphs
parent
ecb0d818
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
GEODE/Visualisation/Graph.py
+62
-0
62 additions, 0 deletions
GEODE/Visualisation/Graph.py
GEODE/Visualisation/__init__.py
+1
-0
1 addition, 0 deletions
GEODE/Visualisation/__init__.py
GEODE/__init__.py
+3
-1
3 additions, 1 deletion
GEODE/__init__.py
guix.scm
+3
-1
3 additions, 1 deletion
guix.scm
with
69 additions
and
2 deletions
GEODE/Visualisation/Graph.py
0 → 100644
+
62
−
0
View file @
98bb5f9f
import
argparse
from
GEODE.Store
import
prepare
from
GEODE.Visualisation.ConfusionMatrix
import
getConfusionMatrix
from
GEODE.Visualisation.Legend
import
trim
from
graphviz
import
Digraph
from
matplotlib.cm
import
ScalarMappable
from
matplotlib.colors
import
Normalize
from
seaborn
import
color_palette
def
hexColorRange
(
vmin
,
vmax
,
cmap
):
mapper
=
ScalarMappable
(
norm
=
Normalize
(
vmin
=
vmin
,
vmax
=
vmax
,
clip
=
True
),
cmap
=
color_palette
(
cmap
,
as_cmap
=
True
)
)
def
toHexRGB
(
color
):
(
r
,
g
,
b
,
_
)
=
mapper
.
to_rgba
(
color
)
return
f
"
#
{
int
(
r
*
255
)
:
02
x
}{
int
(
g
*
255
)
:
02
x
}{
int
(
b
*
255
)
:
02
x
}
"
return
toHexRGB
def
withBorder
(
color
):
border
=
[
"
#3b3b3b
"
]
return
'
:
'
.
join
(
border
+
3
*
[
color
]
+
border
)
def
drawGraph
(
data
,
outputFile
,
cmap
=
'
Blues
'
,
maxWidth
=
None
):
matrix
=
data
[
'
matrix
'
]
labels
=
trim
(
data
[
'
labels
'
],
maxWidth
)
edgeValues
=
[
c
for
row
in
matrix
for
c
in
row
if
c
is
not
None
]
colorize
=
hexColorRange
(
min
(
edgeValues
),
max
(
edgeValues
),
cmap
)
g
=
Digraph
()
g
.
graph_attr
[
'
rankdir
'
]
=
'
LR
'
g
.
node_attr
[
'
fontsize
'
]
=
g
.
edge_attr
[
'
fontsize
'
]
=
'
22
'
g
.
edge_attr
[
'
arrowsize
'
]
=
g
.
edge_attr
[
'
penwidth
'
]
=
'
2
'
dimension
=
len
(
matrix
)
for
i
in
range
(
0
,
dimension
):
g
.
node
(
str
(
i
),
label
=
labels
[
i
])
for
i
in
range
(
0
,
dimension
):
for
j
in
range
(
0
,
len
(
matrix
[
i
])):
link
=
matrix
[
i
][
j
]
if
link
is
not
None
and
link
>
0
:
label
=
f
"
{
link
}
"
if
type
(
link
)
==
int
else
f
"
{
link
:
.
2
f
}
"
color
=
withBorder
(
colorize
(
link
))
g
.
edge
(
str
(
i
),
str
(
j
),
color
=
color
,
label
=
label
)
return
g
.
render
(
prepare
(
outputFile
[:
-
4
]),
format
=
outputFile
[
-
3
:])
def
getArgs
(
arguments
):
cli
=
argparse
.
ArgumentParser
(
prog
=
'
graph
'
,
description
=
"
Draw a graph from its weighted adjacency matrix
"
)
cli
.
add_argument
(
'
inputJSON
'
)
cli
.
add_argument
(
'
outputPNG
'
)
cli
.
add_argument
(
'
-w
'
,
'
--maxWidth
'
,
type
=
int
,
help
=
"
length from which labels will be truncated
"
)
cli
.
add_argument
(
'
-c
'
,
'
--cmap
'
,
help
=
"
color map to use
"
)
return
cli
.
parse_args
(
arguments
)
def
drawGraphCLI
(
arguments
):
args
=
getArgs
(
arguments
)
data
=
getConfusionMatrix
(
args
.
inputJSON
)
drawGraph
(
data
,
args
.
outputPNG
,
maxWidth
=
args
.
maxWidth
,
cmap
=
args
.
cmap
)
This diff is collapsed.
Click to expand it.
GEODE/Visualisation/__init__.py
+
1
−
0
View file @
98bb5f9f
...
...
@@ -3,4 +3,5 @@ from GEODE.Visualisation.ConfusionMatrix import extractConfusionMatrix, \
from
GEODE.Visualisation.DensityProfile
import
densityProfile
,
\
drawDensityProfile
,
plotDensity
from
GEODE.Visualisation.DrawMatrix
import
drawMatrix
from
GEODE.Visualisation.Graph
import
drawGraph
from
GEODE.Visualisation.Legend
import
trim
as
legend
This diff is collapsed.
Click to expand it.
GEODE/__init__.py
+
3
−
1
View file @
98bb5f9f
...
...
@@ -23,16 +23,18 @@ from GEODE.ENE import eneLabels
from
GEODE.Metadata
import
article
,
articleKey
,
paragraph
,
paragraphKey
,
\
fromKey
,
relativePath
,
toKey
,
uid
from
GEODE.Store
import
corpus
,
Directory
,
JSON
,
SelfContained
,
tabular
,
toTSV
from
GEODE.Visualisation
import
densityProfile
,
drawMatrix
,
legend
,
\
from
GEODE.Visualisation
import
densityProfile
,
drawMatrix
,
drawGraph
,
legend
,
\
maxConfusionMatrix
from
GEODE.Visualisation.ConfusionMatrix
import
extractConfusionMatrixCLI
from
GEODE.Visualisation.DensityProfile
import
drawDensityProfileCLI
from
GEODE.Visualisation.DrawMatrix
import
drawMatrixCLI
from
GEODE.Visualisation.Graph
import
drawGraphCLI
commands
=
{
'
confusionMatrix
'
:
extractConfusionMatrixCLI
,
'
densityProfile
'
:
drawDensityProfileCLI
,
'
drawMatrix
'
:
drawMatrixCLI
,
'
graph
'
:
drawGraphCLI
}
def
geopyckCLI
():
...
...
This diff is collapsed.
Click to expand it.
guix.scm
+
3
−
1
View file @
98bb5f9f
(
use-modules
((
gnu
packages
machine-learning
)
#
:select
(
python-pytorch
python-scikit-learn
python-spacy
))
(
use-modules
((
gnu
packages
graphviz
)
#
:select
(
python-graphviz
))
((
gnu
packages
machine-learning
)
#
:select
(
python-pytorch
python-scikit-learn
python-spacy
))
((
gnu
packages
python-science
)
#
:select
(
python-pandas
))
((
gnu
packages
python-xyz
)
#
:select
(
python-matplotlib
python-nltk
...
...
@@ -25,6 +26,7 @@
(
propagated-inputs
(
list
nltk-data-corpora-stopwords
python-frenchleffflemmatizer
python-graphviz
python-matplotlib
python-nltk
python-pandas
...
...
This diff is collapsed.
Click to expand it.
Alice Brenon
@abrenon
mentioned in commit
3945982b
·
1 year ago
mentioned in commit
3945982b
mentioned in commit 3945982b9715858ae08de0f38d2ac6902c1df9c7
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment