eaton-lab / toytree

A minimalist tree plotting library using toyplot graphs
http://eaton-lab.org/toytree
BSD 3-Clause "New" or "Revised" License
164 stars 28 forks source link

Node coloring issue #50

Closed johnpatramanis closed 3 years ago

johnpatramanis commented 3 years ago

Good day, I have an issue when coloring the nodes with a given list of colors. When supplying a list where every object in it is the same color, everything seems to work fine. However when even one object of the list is a different color, it seems to resort to coloring all nodes with the default one ( toytree.colors[0] ). I made a quick test and it seems to confirm this , see code bellow. Tried different color codes (names,rgb, #FFFFF) makes no difference. Tip labels seem to work just fine. Let me know if there is something wrong on my part using the example bellow. Thanks!

` import ete3 import toytree # a tree plotting library import toyplot # a general plotting library import toyplot.pdf import numpy as np import re

tre = toytree.tree("https://eaton-lab.org/data/Cyathophora.tre") #example tree rtre = tre.root(wildcard="prz")

Works when all nodes have the same color

colors = [ toytree.colors[1] for i in rtre.get_node_values('support', 1, 1) ]

canvas, axes, mark = rtre.draw( node_sizes=10, node_colors=colors ) toyplot.pdf.render(canvas, "TEMP_TREE1.pdf") #check plot

Reverts back to default when not all colors are the same, even when its just one thats different

colors = [ toytree.colors[1] for i in rtre.get_node_values('support', 1, 1) ]

colors[-1]=toytree.colors[2] #change last object of list to different color print(colors) #check that indeed last node should have different color

canvas, axes, mark = rtre.draw( node_sizes=10, node_colors=colors ) toyplot.pdf.render(canvas, "TEMP_TREE2.pdf") #check plot

`

jsgounot commented 3 years ago

+1 To add one additional info: This bug arises with the PDF and PNG render, colors render well using jupyter-notebook or using the SVG render (toyplot 0.19.0).

eaton-lab commented 3 years ago

Thanks @jsgounot and @johnpatramanis, I found the bug and it will be fixed in the next versioned update.