# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1250270998 -7200
# Node ID 05e6bc8289a137ec0437429ec8c97f6e2e2c7051
# Parent 8c12696efac8fc61440a57262ee6a95150be6ee4
All the vertices are colored even if vertex_colors did not contain colors for all of them. The first unused color in ranbow() is taken.
There was a small mistake in rgbcolor() where the hexcadecimal values were divided by 256 instead of 255 which lead to "red"!=(1,0,0).
All the colors were wrong and nobody noticed !! :-)
diff -r 8c12696efac8 -r 05e6bc8289a1 sage/graphs/graph_plot.py
a
|
b
|
|
258 | 258 | |
259 | 259 | if 'vertex_colors' not in self._options: |
260 | 260 | if self._options['partition'] is not None: |
261 | | from sage.plot.colors import rainbow |
| 261 | from sage.plot.colors import rainbow,rgbcolor |
262 | 262 | partition = self._options['partition'] |
263 | 263 | l = len(partition) |
264 | 264 | R = rainbow(l) |
… |
… |
|
305 | 305 | for i in vertex_colors: |
306 | 306 | pos += [self._pos[j] for j in vertex_colors[i]] |
307 | 307 | colors += [i]*len(vertex_colors[i]) |
| 308 | |
| 309 | # If all the vertices have not been assigned a color |
| 310 | if len(self._pos)!=len(pos): |
| 311 | from sage.plot.colors import rainbow,rgbcolor |
| 312 | vertex_colors_rgb=[rgbcolor(c) for c in vertex_colors] |
| 313 | for c in rainbow(len(vertex_colors)+1): |
| 314 | if rgbcolor(c) not in vertex_colors_rgb: |
| 315 | break |
| 316 | leftovers=[j for j in self._pos.values() if j not in pos] |
| 317 | pos+=leftovers |
| 318 | colors+=[c]*len(leftovers) |
| 319 | |
308 | 320 | if self._arcdigraph: |
309 | 321 | self._plot_components['vertices'] = [circle(pos[i], self._vertex_radius, fill=True, facecolor=colors[i]) for i in range(len(pos))] |
310 | 322 | else: |
diff -r 8c12696efac8 -r 05e6bc8289a1 sage/plot/colors.py
a
|
b
|
|
273 | 273 | sage: rgbcolor('purple') |
274 | 274 | (0.5, 0.0, 1.0) |
275 | 275 | sage: rgbcolor('#0033ea') |
276 | | (0.0, 0.19921875, 0.9140625) |
| 276 | (0.0, 0.20..., 0.917...) |
277 | 277 | sage: rgbcolor((1,1/2,1/3)) |
278 | 278 | (1.0, 0.5, 0.33333333333333331) |
279 | 279 | """ |
… |
… |
|
284 | 284 | if isinstance(c, str): |
285 | 285 | if len(c) == 7 and c[0] == '#': # html hex color |
286 | 286 | # we use Integer instead of 0x eval for security reasons |
287 | | return tuple([int(c[i:i+2], base=16)/float(256) for i in [1,3,5]]) |
| 287 | return tuple([int(c[i:i+2], base=16)/float(255) for i in [1,3,5]]) |
288 | 288 | try: |
289 | 289 | return colors[c] |
290 | 290 | except KeyError: |
… |
… |
|
310 | 310 | sage: Color(0.5,0,1) |
311 | 311 | RGB color (0.5, 0.0, 1.0) |
312 | 312 | sage: Color('#8000ff') |
313 | | RGB color (0.5, 0.0, 0.99609375) |
| 313 | RGB color (0.50..., 0.0, 1.0) |
314 | 314 | """ |
315 | 315 | if g is None and b is None: |
316 | 316 | self.__rgb = rgbcolor(r) |
… |
… |
|
324 | 324 | EXAMPLES:: |
325 | 325 | |
326 | 326 | sage: Color('#8000ff').__repr__() |
327 | | 'RGB color (0.5, 0.0, 0.99609375)' |
| 327 | 'RGB color (0.50..., 0.0, 1.0)' |
328 | 328 | """ |
329 | 329 | return "RGB color %s"%(self.__rgb,) |
330 | 330 | |
… |
… |
|
337 | 337 | EXAMPLES:: |
338 | 338 | |
339 | 339 | sage: Color('#8000ff').rgb() |
340 | | (0.5, 0.0, 0.99609375) |
| 340 | (0.50..., 0.0, 1.0) |
341 | 341 | """ |
342 | 342 | return self.__rgb |
343 | 343 | |