-
Notifications
You must be signed in to change notification settings - Fork 28
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
Return ToytreeMark.markers list with edge and node marks for optional legend construction #51
Comments
I have further figured out that >>> m2.markers[0]
<marker shape='s' mstyle='fill:rgb(0%,50.2%,0%);fill-opacity:1.0;opacity:1;stroke:rgb(0%,50.2%,0%);stroke-opac
ity:1.0'/> But I can't find anything on |
Ok, so I was unable to obtain a markers = [toyplot.marker.create(shape="o", size=18, mstyle={"fill": x}) for x in my_palette]
legend_markers = list(zip(bootstraps, markers))
canvas.legend(legend_markers,
corner=("top-right", 20, 170, 140)) Where |
Hey @StuntsPT, Great solution! The legend creation in toyplot is not super intuitive. Saving the marker objects and passing them to the legend function is easiest, but not always doable when you have complex plots. Your approach of making custom marker objects is a great solution. I was very back-and-forth when designing toytree in deciding whether to return portions of tree drawings as a collection of separate toyplot marker objects (e.g., a graph for the tree, text for the tips, scatterplot for nodes, etc.) versus creating a custom ToyTreeMark class object. In v1 I followed the first approach, whereas v2 does the latter. The custom marker object approach had some significant advantages for the size and speed of creation of the objects, and for setting margin spacing around them. That being said, I think you are right that the mark.markers list is a clear place for storing the underlying toyplot markers that compose the nodes or edges, but its something that I never filled (it's just an inherited feature of the Mark class). I definitely welcome any contributions to the docs or source, I'm really interested in getting more developers involved with toytree. Shoot me an email if you're interested and I can fill you in on some of the future plans. I'll leave this issue open for now since I think filling the |
Thanks!
It took me a while to get my head around it, but I managed a work around, that doesn't make me want to puke afterwards. =-)
Your v2 also seems like the best approach for extending the original markers if required in the future.
Cool, expect an email as soon as I get some breathing space. =-)
In that case, maybe altering the issue title is reasonable in order to make it clear what is being addressed here? |
This is a help request, but I cannot seem to find in the docs how to do this.
I want to add a legend to my tree, to explain what each mode colour means (they have different colours based on support value).
I have looked at toytree's docs, and realized I had to add it via toyplot directly. So far so good. I dove into pyplot's docs, and found this:
https://toyplot.readthedocs.io/en/stable/labels-and-legends.html#canvas-legends
and this:
https://toyplot.readthedocs.io/en/stable/toyplot.canvas.html#toyplot.canvas.Canvas.legend
This led me to the
canvas
object that is returned byIn order to draw a legend I can use toyplot's API and call
canvas.legend()
. This requires (at least) a list ofentries
each being a tuple containing a custom string and amarker
/mark
object. If I prove it themark
object returned bytre.draw()
, I can see the text string being draw in the canvas, but what I can't seem to figure out is how can I call each of the node styles present in my tree in order to label each of them with a custom string.Can you please assist me in obtaining this information?
Thank you very much in advance!
The text was updated successfully, but these errors were encountered: