Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
graph-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
40
Issues
40
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tiago Peixoto
graph-tool
Commits
d01a66e1
Commit
d01a66e1
authored
Aug 10, 2017
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
graph_draw(): Add support for overriding alpha values of color maps
parent
0932e4a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
10 deletions
+19
-10
src/graph_tool/draw/cairo_draw.py
src/graph_tool/draw/cairo_draw.py
+19
-10
No files found.
src/graph_tool/draw/cairo_draw.py
View file @
d01a66e1
...
@@ -319,6 +319,11 @@ def centered_rotation(g, pos, text_pos=True):
...
@@ -319,6 +319,11 @@ def centered_rotation(g, pos, text_pos=True):
return
angle
return
angle
def
_convert
(
attr
,
val
,
cmap
,
pmap_default
=
False
,
g
=
None
,
k
=
None
):
def
_convert
(
attr
,
val
,
cmap
,
pmap_default
=
False
,
g
=
None
,
k
=
None
):
try
:
cmap
,
alpha
=
cmap
except
TypeError
:
alpha
=
None
if
attr
==
vertex_attrs
.
shape
:
if
attr
==
vertex_attrs
.
shape
:
new_val
=
shape_from_prop
(
val
,
vertex_shape
)
new_val
=
shape_from_prop
(
val
,
vertex_shape
)
if
pmap_default
and
not
isinstance
(
val
,
PropertyMap
):
if
pmap_default
and
not
isinstance
(
val
,
PropertyMap
):
...
@@ -350,7 +355,8 @@ def _convert(attr, val, cmap, pmap_default=False, g=None, k=None):
...
@@ -350,7 +355,8 @@ def _convert(attr, val, cmap, pmap_default=False, g=None, k=None):
if
rg
[
0
]
==
rg
[
1
]:
if
rg
[
0
]
==
rg
[
1
]:
rg
[
1
]
=
1
rg
[
1
]
=
1
map_property_values
(
val
,
new_val
,
map_property_values
(
val
,
new_val
,
lambda
y
:
flatten
([
cmap
((
x
-
rg
[
0
])
/
(
rg
[
1
]
-
rg
[
0
]))
for
x
in
y
]))
lambda
y
:
flatten
([
cmap
((
x
-
rg
[
0
])
/
(
rg
[
1
]
-
rg
[
0
]),
alpha
=
alpha
)
for
x
in
y
]))
return
new_val
return
new_val
if
val
.
value_type
()
==
"vector<string>"
:
if
val
.
value_type
()
==
"vector<string>"
:
g
=
val
.
get_graph
()
g
=
val
.
get_graph
()
...
@@ -422,7 +428,8 @@ def _convert(attr, val, cmap, pmap_default=False, g=None, k=None):
...
@@ -422,7 +428,8 @@ def _convert(attr, val, cmap, pmap_default=False, g=None, k=None):
prop
=
g
.
new_vertex_property
(
"vector<double>"
)
prop
=
g
.
new_vertex_property
(
"vector<double>"
)
else
:
else
:
prop
=
g
.
new_edge_property
(
"vector<double>"
)
prop
=
g
.
new_edge_property
(
"vector<double>"
)
map_property_values
(
nval
,
prop
,
lambda
x
:
cmap
(
cnorm
(
x
)))
map_property_values
(
nval
,
prop
,
lambda
x
:
cmap
(
cnorm
(
x
),
alpha
=
alpha
))
new_val
=
prop
new_val
=
prop
elif
val
.
value_type
()
==
"string"
:
elif
val
.
value_type
()
==
"string"
:
g
=
val
.
get_graph
()
g
=
val
.
get_graph
()
...
@@ -547,8 +554,7 @@ def cairo_draw(g, pos, cr, vprops=None, eprops=None, vorder=None, eorder=None,
...
@@ -547,8 +554,7 @@ def cairo_draw(g, pos, cr, vprops=None, eprops=None, vorder=None, eorder=None,
nodesfirst
=
False
,
vcmap
=
default_cm
,
ecmap
=
default_cm
,
nodesfirst
=
False
,
vcmap
=
default_cm
,
ecmap
=
default_cm
,
loop_angle
=
numpy
.
nan
,
parallel_distance
=
None
,
fit_view
=
False
,
loop_angle
=
numpy
.
nan
,
parallel_distance
=
None
,
fit_view
=
False
,
res
=
0
,
max_render_time
=-
1
,
**
kwargs
):
res
=
0
,
max_render_time
=-
1
,
**
kwargs
):
r
"""
r
"""Draw a graph to a :mod:`cairo` context.
Draw a graph to a :mod:`cairo` context.
Parameters
Parameters
----------
----------
...
@@ -573,10 +579,12 @@ def cairo_draw(g, pos, cr, vprops=None, eprops=None, vorder=None, eorder=None,
...
@@ -573,10 +579,12 @@ def cairo_draw(g, pos, cr, vprops=None, eprops=None, vorder=None, eorder=None,
If provided, defines the relative order in which the edges are drawn.
If provided, defines the relative order in which the edges are drawn.
nodesfirst : bool (optional, default: ``False``)
nodesfirst : bool (optional, default: ``False``)
If ``True``, the vertices are drawn first, otherwise the edges are.
If ``True``, the vertices are drawn first, otherwise the edges are.
vcmap : :class:`matplotlib.colors.Colormap` (optional, default: :class:`default_cm`)
vcmap : :class:`matplotlib.colors.Colormap` or tuple (optional, default: :class:`default_cm`)
Vertex color map.
Vertex color map. Optionally, this may be a
ecmap : :class:`matplotlib.colors.Colormap` (optional, default: :class:`default_cm`)
(:class:`matplotlib.colors.Colormap`, alpha) tuple.
Edge color map.
ecmap : :class:`matplotlib.colors.Colormap` or tuple (optional, default: :class:`default_cm`)
Edge color map. Optionally, this may be a
(:class:`matplotlib.colors.Colormap`, alpha) tuple.
loop_angle : float or :class:`~graph_tool.PropertyMap` (optional, default: ``nan``)
loop_angle : float or :class:`~graph_tool.PropertyMap` (optional, default: ``nan``)
Angle used to draw self-loops. If ``nan`` is given, they will be placed
Angle used to draw self-loops. If ``nan`` is given, they will be placed
radially from the center of the layout.
radially from the center of the layout.
...
@@ -612,6 +620,7 @@ def cairo_draw(g, pos, cr, vprops=None, eprops=None, vorder=None, eorder=None,
...
@@ -612,6 +620,7 @@ def cairo_draw(g, pos, cr, vprops=None, eprops=None, vorder=None, eorder=None,
If ``max_render_time`` is nonnegative, this will be an iterator that will
If ``max_render_time`` is nonnegative, this will be an iterator that will
perform part of the drawing at each step, so that each iteration takes
perform part of the drawing at each step, so that each iteration takes
at most ``max_render_time`` milliseconds.
at most ``max_render_time`` milliseconds.
"""
"""
if
vorder
is
not
None
:
if
vorder
is
not
None
:
...
@@ -1060,7 +1069,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
...
@@ -1060,7 +1069,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
eprops
[
"text_distance"
]
=
pw
*
2
eprops
[
"text_distance"
]
=
pw
*
2
if
"text"
in
vprops
and
(
"text_color"
not
in
vprops
or
vprops
[
"text_color"
]
==
"auto"
):
if
"text"
in
vprops
and
(
"text_color"
not
in
vprops
or
vprops
[
"text_color"
]
==
"auto"
):
vcmap
=
kwargs
.
get
(
"vcmap"
,
matplotlib
.
cm
.
jet
)
vcmap
=
kwargs
.
get
(
"vcmap"
,
default_cm
)
bg
=
_convert
(
vertex_attrs
.
fill_color
,
bg
=
_convert
(
vertex_attrs
.
fill_color
,
vprops
.
get
(
"fill_color"
,
_vdefaults
[
"fill_color"
]),
vprops
.
get
(
"fill_color"
,
_vdefaults
[
"fill_color"
]),
vcmap
)
vcmap
)
...
@@ -1070,7 +1079,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
...
@@ -1070,7 +1079,7 @@ def graph_draw(g, pos=None, vprops=None, eprops=None, vorder=None, eorder=None,
_vdefaults
[
"text_position"
]),
_vdefaults
[
"text_position"
]),
bg_color
)
bg_color
)
if
mplfig
:
if
mplfig
is
not
None
:
ax
=
None
ax
=
None
if
isinstance
(
mplfig
,
matplotlib
.
figure
.
Figure
):
if
isinstance
(
mplfig
,
matplotlib
.
figure
.
Figure
):
ctr
=
ax
=
mplfig
.
gca
()
ctr
=
ax
=
mplfig
.
gca
()
...
...
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