Skip to content

Node colours in draw_svg() #2330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gtsambos opened this issue Jun 9, 2022 · 5 comments
Closed

Node colours in draw_svg() #2330

gtsambos opened this issue Jun 9, 2022 · 5 comments

Comments

@gtsambos
Copy link
Member

gtsambos commented Jun 9, 2022

It would be nice to have the facility to colour the nodes in draw_svg(), like you still can with draw(). I'm happy to be assigned to this, but can't tackle it immediately.

@jeromekelleher
Copy link
Member

I think we consciously dropped this in favour of the more powerful CSS based approach @gtsambos, like in tshi example

It's not as easy to use, but it's infinitely more flexible.

Is this a fair summary @hyanwong?

@jeromekelleher
Copy link
Member

Related: #579

@hyanwong
Copy link
Member

hyanwong commented Jun 9, 2022

Yes, that's right. It seemed better not to set specific attributes like colour by a proliferation of parameters, when you can easily CSS it. There's code showing how to do it as the first example here: https://tskit.dev/tutorials/viz.html#styling

Suggestions on how to make this easier are most welcome. Perhaps the example there is too complicated? All you really need is


ts.draw_svg(style=".node.p0 > .sym {fill: red} .node.p1 > .sym {fill: green} .node.p2 > .sym {fill: blue}")

@hyanwong
Copy link
Member

hyanwong commented Jun 9, 2022

Or if you are want to use matplotlib colours, for example:

import matplotlib.colors as mcolors
ts.draw_svg(style="".join([
    f".node.p{p.id}>.sym {{fill: {col}}"
    for col, p in zip(mcolors.TABLEAU_COLORS.values(), ts.populations())
])

@benjeffery
Copy link
Member

Closing this as CSS is the preferred route. Re-open if anyone feels strongly!

@benjeffery benjeffery closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants