Commit 124bbe06 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Change default colormap

parent 9b147c0d
...@@ -138,6 +138,10 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6, ...@@ -138,6 +138,10 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6,
Examples Examples
-------- --------
.. testsetup:: pagerank
import matplotlib
.. doctest:: pagerank .. doctest:: pagerank
>>> g = gt.collection.data["polblogs"] >>> g = gt.collection.data["polblogs"]
...@@ -145,7 +149,8 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6, ...@@ -145,7 +149,8 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6,
>>> pr = gt.pagerank(g) >>> pr = gt.pagerank(g)
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=pr, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=pr,
... vertex_size=gt.prop_to_size(pr, mi=5, ma=15), ... vertex_size=gt.prop_to_size(pr, mi=5, ma=15),
... vorder=pr, output="polblogs_pr.pdf") ... vorder=pr, vcmap=matplotlib.cm.gist_heat,
... output="polblogs_pr.pdf")
<...> <...>
.. testcode:: pagerank .. testcode:: pagerank
...@@ -153,7 +158,8 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6, ...@@ -153,7 +158,8 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6,
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=pr, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=pr,
vertex_size=gt.prop_to_size(pr, mi=5, ma=15), vertex_size=gt.prop_to_size(pr, mi=5, ma=15),
vorder=pr, output="polblogs_pr.png") vorder=pr, vcmap=matplotlib.cm.gist_heat,
output="polblogs_pr.png")
.. figure:: polblogs_pr.* .. figure:: polblogs_pr.*
...@@ -172,7 +178,8 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6, ...@@ -172,7 +178,8 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6,
>>> pr = gt.pagerank(g, pers=p) >>> pr = gt.pagerank(g, pers=p)
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=pr, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=pr,
... vertex_size=gt.prop_to_size(pr, mi=5, ma=15), ... vertex_size=gt.prop_to_size(pr, mi=5, ma=15),
... vorder=pr, output="polblogs_pr_pers.pdf") ... vorder=pr, vcmap=matplotlib.cm.gist_heat,
... output="polblogs_pr_pers.pdf")
<...> <...>
.. testcode:: pagerank .. testcode:: pagerank
...@@ -180,6 +187,7 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6, ...@@ -180,6 +187,7 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6,
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=pr, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=pr,
vertex_size=gt.prop_to_size(pr, mi=5, ma=15), vertex_size=gt.prop_to_size(pr, mi=5, ma=15),
vcmap=matplotlib.cm.gist_heat,
vorder=pr, output="polblogs_pr_pers.png") vorder=pr, output="polblogs_pr_pers.png")
...@@ -275,6 +283,10 @@ def betweenness(g, vprop=None, eprop=None, weight=None, norm=True): ...@@ -275,6 +283,10 @@ def betweenness(g, vprop=None, eprop=None, weight=None, norm=True):
Examples Examples
-------- --------
.. testsetup:: betweenness
import matplotlib
.. doctest:: betweenness .. doctest:: betweenness
>>> g = gt.collection.data["polblogs"] >>> g = gt.collection.data["polblogs"]
...@@ -283,6 +295,7 @@ def betweenness(g, vprop=None, eprop=None, weight=None, norm=True): ...@@ -283,6 +295,7 @@ def betweenness(g, vprop=None, eprop=None, weight=None, norm=True):
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=vp, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=vp,
... vertex_size=gt.prop_to_size(vp, mi=5, ma=15), ... vertex_size=gt.prop_to_size(vp, mi=5, ma=15),
... edge_pen_width=gt.prop_to_size(ep, mi=0.5, ma=5), ... edge_pen_width=gt.prop_to_size(ep, mi=0.5, ma=5),
... vcmap=matplotlib.cm.gist_heat,
... vorder=vp, output="polblogs_betweenness.pdf") ... vorder=vp, output="polblogs_betweenness.pdf")
<...> <...>
...@@ -292,6 +305,7 @@ def betweenness(g, vprop=None, eprop=None, weight=None, norm=True): ...@@ -292,6 +305,7 @@ def betweenness(g, vprop=None, eprop=None, weight=None, norm=True):
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=vp, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=vp,
vertex_size=gt.prop_to_size(vp, mi=5, ma=15), vertex_size=gt.prop_to_size(vp, mi=5, ma=15),
edge_pen_width=gt.prop_to_size(ep, mi=0.5, ma=5), edge_pen_width=gt.prop_to_size(ep, mi=0.5, ma=5),
vcmap=matplotlib.cm.gist_heat,
vorder=vp, output="polblogs_betweenness.png") vorder=vp, output="polblogs_betweenness.png")
...@@ -392,6 +406,10 @@ def closeness(g, weight=None, source=None, vprop=None, norm=True, harmonic=False ...@@ -392,6 +406,10 @@ def closeness(g, weight=None, source=None, vprop=None, norm=True, harmonic=False
Examples Examples
-------- --------
.. testsetup:: closeness
import matplotlib
.. doctest:: closeness .. doctest:: closeness
>>> g = gt.collection.data["polblogs"] >>> g = gt.collection.data["polblogs"]
...@@ -399,6 +417,7 @@ def closeness(g, weight=None, source=None, vprop=None, norm=True, harmonic=False ...@@ -399,6 +417,7 @@ def closeness(g, weight=None, source=None, vprop=None, norm=True, harmonic=False
>>> c = gt.closeness(g) >>> c = gt.closeness(g)
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=c, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=c,
... vertex_size=gt.prop_to_size(c, mi=5, ma=15), ... vertex_size=gt.prop_to_size(c, mi=5, ma=15),
... vcmap=matplotlib.cm.gist_heat,
... vorder=c, output="polblogs_closeness.pdf") ... vorder=c, output="polblogs_closeness.pdf")
<...> <...>
...@@ -407,6 +426,7 @@ def closeness(g, weight=None, source=None, vprop=None, norm=True, harmonic=False ...@@ -407,6 +426,7 @@ def closeness(g, weight=None, source=None, vprop=None, norm=True, harmonic=False
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=c, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=c,
vertex_size=gt.prop_to_size(c, mi=5, ma=15), vertex_size=gt.prop_to_size(c, mi=5, ma=15),
vcmap=matplotlib.cm.gist_heat,
vorder=c, output="polblogs_closeness.png") vorder=c, output="polblogs_closeness.png")
...@@ -566,9 +586,11 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None): ...@@ -566,9 +586,11 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None):
Examples Examples
-------- --------
.. testsetup:: eigenvector .. testsetup:: eigenvector
np.random.seed(42) np.random.seed(42)
import matplotlib
.. doctest:: eigenvector .. doctest:: eigenvector
...@@ -581,6 +603,7 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None): ...@@ -581,6 +603,7 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None):
729.229595705175 729.229595705175
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x,
... vertex_size=gt.prop_to_size(x, mi=5, ma=15), ... vertex_size=gt.prop_to_size(x, mi=5, ma=15),
... vcmap=matplotlib.cm.gist_heat,
... vorder=x, output="polblogs_eigenvector.pdf") ... vorder=x, output="polblogs_eigenvector.pdf")
<...> <...>
...@@ -589,6 +612,7 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None): ...@@ -589,6 +612,7 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None):
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x,
vertex_size=gt.prop_to_size(x, mi=5, ma=15), vertex_size=gt.prop_to_size(x, mi=5, ma=15),
vcmap=matplotlib.cm.gist_heat,
vorder=x, output="polblogs_eigenvector.png") vorder=x, output="polblogs_eigenvector.png")
...@@ -689,6 +713,7 @@ def katz(g, alpha=0.01, beta=None, weight=None, vprop=None, epsilon=1e-6, ...@@ -689,6 +713,7 @@ def katz(g, alpha=0.01, beta=None, weight=None, vprop=None, epsilon=1e-6,
.. testsetup:: katz .. testsetup:: katz
np.random.seed(42) np.random.seed(42)
import matplotlib
.. doctest:: katz .. doctest:: katz
...@@ -699,6 +724,7 @@ def katz(g, alpha=0.01, beta=None, weight=None, vprop=None, epsilon=1e-6, ...@@ -699,6 +724,7 @@ def katz(g, alpha=0.01, beta=None, weight=None, vprop=None, epsilon=1e-6,
>>> x = gt.katz(g, weight=w) >>> x = gt.katz(g, weight=w)
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x,
... vertex_size=gt.prop_to_size(x, mi=5, ma=15), ... vertex_size=gt.prop_to_size(x, mi=5, ma=15),
... vcmap=matplotlib.cm.gist_heat,
... vorder=x, output="polblogs_katz.pdf") ... vorder=x, output="polblogs_katz.pdf")
<...> <...>
...@@ -707,6 +733,7 @@ def katz(g, alpha=0.01, beta=None, weight=None, vprop=None, epsilon=1e-6, ...@@ -707,6 +733,7 @@ def katz(g, alpha=0.01, beta=None, weight=None, vprop=None, epsilon=1e-6,
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x,
vertex_size=gt.prop_to_size(x, mi=5, ma=15), vertex_size=gt.prop_to_size(x, mi=5, ma=15),
vcmap=matplotlib.cm.gist_heat,
vorder=x, output="polblogs_katz.png") vorder=x, output="polblogs_katz.png")
...@@ -806,6 +833,10 @@ def hits(g, weight=None, xprop=None, yprop=None, epsilon=1e-6, max_iter=None): ...@@ -806,6 +833,10 @@ def hits(g, weight=None, xprop=None, yprop=None, epsilon=1e-6, max_iter=None):
Examples Examples
-------- --------
.. testsetup:: hits
import matplotlib
.. doctest:: hits .. doctest:: hits
>>> g = gt.collection.data["polblogs"] >>> g = gt.collection.data["polblogs"]
...@@ -813,10 +844,12 @@ def hits(g, weight=None, xprop=None, yprop=None, epsilon=1e-6, max_iter=None): ...@@ -813,10 +844,12 @@ def hits(g, weight=None, xprop=None, yprop=None, epsilon=1e-6, max_iter=None):
>>> ee, x, y = gt.hits(g) >>> ee, x, y = gt.hits(g)
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x,
... vertex_size=gt.prop_to_size(x, mi=5, ma=15), ... vertex_size=gt.prop_to_size(x, mi=5, ma=15),
... vcmap=matplotlib.cm.gist_heat,
... vorder=x, output="polblogs_hits_auths.pdf") ... vorder=x, output="polblogs_hits_auths.pdf")
<...> <...>
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=y, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=y,
... vertex_size=gt.prop_to_size(y, mi=5, ma=15), ... vertex_size=gt.prop_to_size(y, mi=5, ma=15),
... vcmap=matplotlib.cm.gist_heat,
... vorder=y, output="polblogs_hits_hubs.pdf") ... vorder=y, output="polblogs_hits_hubs.pdf")
<...> <...>
...@@ -825,20 +858,22 @@ def hits(g, weight=None, xprop=None, yprop=None, epsilon=1e-6, max_iter=None): ...@@ -825,20 +858,22 @@ def hits(g, weight=None, xprop=None, yprop=None, epsilon=1e-6, max_iter=None):
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x,
vertex_size=gt.prop_to_size(x, mi=5, ma=15), vertex_size=gt.prop_to_size(x, mi=5, ma=15),
vcmap=matplotlib.cm.gist_heat,
vorder=x, output="polblogs_hits_auths.png") vorder=x, output="polblogs_hits_auths.png")
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=y, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=y,
vertex_size=gt.prop_to_size(y, mi=5, ma=15), vertex_size=gt.prop_to_size(y, mi=5, ma=15),
vcmap=matplotlib.cm.gist_heat,
vorder=y, output="polblogs_hits_hubs.png") vorder=y, output="polblogs_hits_hubs.png")
.. figure:: polblogs_hits_auths.* .. figure:: polblogs_hits_auths.*
:align: left :align: center
HITS authority values of the a political blogs network of HITS authority values of the a political blogs network of
[adamic-polblogs]_. [adamic-polblogs]_.
.. figure:: polblogs_hits_hubs.* .. figure:: polblogs_hits_hubs.*
:align: right :align: center
HITS hub values of the a political blogs network of [adamic-polblogs]_. HITS hub values of the a political blogs network of [adamic-polblogs]_.
...@@ -928,6 +963,7 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epsilon=1e-6, max_iter=0, ...@@ -928,6 +963,7 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epsilon=1e-6, max_iter=0,
.. testsetup:: eigentrust .. testsetup:: eigentrust
np.random.seed(42) np.random.seed(42)
import matplotlib
.. doctest:: eigentrust .. doctest:: eigentrust
...@@ -938,6 +974,7 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epsilon=1e-6, max_iter=0, ...@@ -938,6 +974,7 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epsilon=1e-6, max_iter=0,
>>> t = gt.eigentrust(g, w) >>> t = gt.eigentrust(g, w)
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=t, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=t,
... vertex_size=gt.prop_to_size(t, mi=5, ma=15), ... vertex_size=gt.prop_to_size(t, mi=5, ma=15),
... vcmap=matplotlib.cm.gist_heat,
... vorder=t, output="polblogs_eigentrust.pdf") ... vorder=t, output="polblogs_eigentrust.pdf")
<...> <...>
...@@ -946,6 +983,7 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epsilon=1e-6, max_iter=0, ...@@ -946,6 +983,7 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epsilon=1e-6, max_iter=0,
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=t, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=t,
vertex_size=gt.prop_to_size(t, mi=5, ma=15), vertex_size=gt.prop_to_size(t, mi=5, ma=15),
vcmap=matplotlib.cm.gist_heat,
vorder=t, output="polblogs_eigentrust.png") vorder=t, output="polblogs_eigentrust.png")
...@@ -1055,6 +1093,7 @@ def trust_transitivity(g, trust_map, source=None, target=None, vprop=None): ...@@ -1055,6 +1093,7 @@ def trust_transitivity(g, trust_map, source=None, target=None, vprop=None):
.. testsetup:: trust_transitivity .. testsetup:: trust_transitivity
np.random.seed(42) np.random.seed(42)
import matplotlib
.. doctest:: trust_transitivity .. doctest:: trust_transitivity
...@@ -1068,6 +1107,7 @@ def trust_transitivity(g, trust_map, source=None, target=None, vprop=None): ...@@ -1068,6 +1107,7 @@ def trust_transitivity(g, trust_map, source=None, target=None, vprop=None):
>>> t = gt.trust_transitivity(g, w, source=g.vertex(42)) >>> t = gt.trust_transitivity(g, w, source=g.vertex(42))
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=t, >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=t,
... vertex_size=gt.prop_to_size(t, mi=5, ma=15), ... vertex_size=gt.prop_to_size(t, mi=5, ma=15),
... vcmap=matplotlib.cm.gist_heat,
... vorder=t, output="polblogs_trust_transitivity.pdf") ... vorder=t, output="polblogs_trust_transitivity.pdf")
<...> <...>
...@@ -1076,6 +1116,7 @@ def trust_transitivity(g, trust_map, source=None, target=None, vprop=None): ...@@ -1076,6 +1116,7 @@ def trust_transitivity(g, trust_map, source=None, target=None, vprop=None):
gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=t, gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=t,
vertex_size=gt.prop_to_size(t, mi=5, ma=15), vertex_size=gt.prop_to_size(t, mi=5, ma=15),
vcmap=matplotlib.cm.gist_heat,
vorder=t, output="polblogs_trust_transitivity.png") vorder=t, output="polblogs_trust_transitivity.png")
......
...@@ -81,11 +81,10 @@ from .. dl_import import dl_import ...@@ -81,11 +81,10 @@ from .. dl_import import dl_import
dl_import("from . import libgraph_tool_layout") dl_import("from . import libgraph_tool_layout")
__all__ = ["graph_draw", "graphviz_draw", __all__ = ["graph_draw", "graphviz_draw", "fruchterman_reingold_layout",
"fruchterman_reingold_layout", "arf_layout", "sfdp_layout", "random_layout", "radial_tree_layout",
"arf_layout", "sfdp_layout", "random_layout", "cairo_draw", "prop_to_size", "get_hierarchy_control_points",
"radial_tree_layout", "default_cm"]
"cairo_draw", "prop_to_size", "get_hierarchy_control_points"]
def random_layout(g, shape=None, pos=None, dim=2): def random_layout(g, shape=None, pos=None, dim=2):
...@@ -767,7 +766,7 @@ def radial_tree_layout(g, root, weighted=False, r=1.): ...@@ -767,7 +766,7 @@ def radial_tree_layout(g, root, weighted=False, r=1.):
return g.own_property(pos) return g.own_property(pos)
try: try:
from .cairo_draw import graph_draw, cairo_draw, get_hierarchy_control_points from .cairo_draw import graph_draw, cairo_draw, get_hierarchy_control_points, default_cm
except ImportError: except ImportError:
pass pass
...@@ -791,7 +790,7 @@ def prop_to_size(prop, mi=0, ma=5, log=False, power=0.5): ...@@ -791,7 +790,7 @@ def prop_to_size(prop, mi=0, ma=5, log=False, power=0.5):
y = mi + (ma - mi) \left(\frac{x_i - min(x)} {max(x) - min(x)}\right)^\text{power} y = mi + (ma - mi) \left(\frac{x_i - min(x)} {max(x) - min(x)}\right)^\text{power}
If `log=True`, the natural logarithm of the property values are used instead. If `log=True`, the natural logarithm of the property values is used instead.
""" """
prop = prop.copy(value_type="double") prop = prop.copy(value_type="double")
......
...@@ -34,6 +34,7 @@ except ImportError: ...@@ -34,6 +34,7 @@ except ImportError:
warnings.warn(msg, ImportWarning) warnings.warn(msg, ImportWarning)
raise raise
default_cm = None
try: try:
import matplotlib.cm import matplotlib.cm
import matplotlib.colors import matplotlib.colors
...@@ -297,14 +298,14 @@ def _convert(attr, val, cmap): ...@@ -297,14 +298,14 @@ def _convert(attr, val, cmap):
return val return val
if val.value_type() in ["int32_t", "int64_t", "double", if val.value_type() in ["int32_t", "int64_t", "double",
"long double", "unsigned long", "bool"]: "long double", "unsigned long", "bool"]:
if val.fa is None: try:
vrange = [val.fa.min(), val.fa.max()]
except ValueError:
vrange = val[val.get_graph().vertex(0)] vrange = val[val.get_graph().vertex(0)]
vrange = [vrange, vrange] vrange = [vrange, vrange]
for v in val.get_graph().vertices(): for v in val.get_graph().vertices():
vrange[0] = min(vrange[0], val[v]) vrange[0] = min(vrange[0], val[v])
vrange[1] = max(vrange[1], val[v]) vrange[1] = max(vrange[1], val[v])
else:
vrange = [val.fa.min(), val.fa.max()]
cnorm = matplotlib.colors.Normalize(vmin=vrange[0], cnorm = matplotlib.colors.Normalize(vmin=vrange[0],
vmax=vrange[1]) vmax=vrange[1])
if val.key_type() == "v": if val.key_type() == "v":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment