Skip to content

Commit 441341f

Browse files
committed
Merge branch 'master' into naspert-nn_refactor
2 parents f69c694 + 9950c66 commit 441341f

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ matrix:
1919
addons:
2020
apt:
2121
packages:
22+
- libqt5gui5 # pyqt5>5.11 otherwise cannot load the xcb platform plugin
2223
- libflann-dev
2324

2425
install:

pygsp/plotting.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ def _plot_graph(G, vertex_color, vertex_size, highlight,
299299
Signal to plot as vertex color (length is the number of vertices).
300300
If None, vertex color is set to `graph.plotting['vertex_color']`.
301301
Alternatively, a color can be set in any format accepted by matplotlib.
302+
Each vertex color can by specified by an RGB(A) array of dimension
303+
`n_vertices` x 3 (or 4).
302304
vertex_size : array-like or int
303305
Signal to plot as vertex size (length is the number of vertices).
304306
Vertex size ranges from 0.5 to 2 times `graph.plotting['vertex_size']`.
@@ -319,6 +321,8 @@ def _plot_graph(G, vertex_color, vertex_size, highlight,
319321
ranges from 0.2 to 0.9.
320322
If None, edge color is set to `graph.plotting['edge_color']`.
321323
Alternatively, a color can be set in any format accepted by matplotlib.
324+
Each edge color can by specified by an RGB(A) array of dimension
325+
`n_edges` x 3 (or 4).
322326
Only available with the matplotlib backend.
323327
edge_width : array-like or int
324328
Signal to plot as edge width (length is the number of edges).
@@ -405,20 +409,26 @@ def normalize(x):
405409
return np.full(x.shape, 0.5)
406410
return 0.75 * (x - x.min()) / ptp + 0.25
407411

408-
def is_single_color(color):
412+
def is_color(color):
413+
409414
if backend == 'matplotlib':
410415
mpl, _, _ = _import_plt()
411-
return mpl.colors.is_color_like(color)
412-
elif backend == 'pyqtgraph':
413-
# No support (yet) for single color with pyqtgraph.
414-
return False
416+
if mpl.colors.is_color_like(color):
417+
return True # single color
418+
try:
419+
return all(map(mpl.colors.is_color_like, color)) # color list
420+
except TypeError:
421+
return False # e.g., color is an int
422+
423+
else:
424+
return False # No support for pyqtgraph (yet).
415425

416426
if vertex_color is None:
417427
limits = [0, 0]
418428
colorbar = False
419429
if backend == 'matplotlib':
420430
vertex_color = (G.plotting['vertex_color'],)
421-
elif is_single_color(vertex_color):
431+
elif is_color(vertex_color):
422432
limits = [0, 0]
423433
colorbar = False
424434
else:
@@ -438,8 +448,8 @@ def is_single_color(color):
438448

439449
if edge_color is None:
440450
edge_color = (G.plotting['edge_color'],)
441-
elif not is_single_color(edge_color):
442-
edge_color = np.array(edge_color).squeeze()
451+
elif not is_color(edge_color):
452+
edge_color = np.asarray(edge_color).squeeze()
443453
check_shape(edge_color, 'Edge color', G.n_edges)
444454
edge_color = 0.9 * normalize(edge_color)
445455
edge_color = [

pygsp/tests/test_plotting.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,14 @@ def test_signals(self):
116116
G.plot()
117117
def test_color(param, length):
118118
for value in ['r', 4*(.5,), length*(2,), np.ones([1, length]),
119-
np.random.RandomState(42).uniform(size=length)]:
119+
np.random.RandomState(42).uniform(size=length),
120+
np.ones([length, 3]), ["red"] * length,
121+
np.random.RandomState(42).rand(length, 4)]:
120122
params = {param: value}
121123
G.plot(**params)
122124
for value in [10, (0.5, 0.5), np.ones([length, 2]),
123-
np.ones([2, length, 3])]:
125+
np.ones([2, length, 3]),
126+
np.ones([length, 3]) * 1.1]:
124127
params = {param: value}
125128
self.assertRaises(ValueError, G.plot, **params)
126129
for value in ['r', 4*(.5)]:

0 commit comments

Comments
 (0)