Skip to content
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

Adding y_axis scale function #318

Open
wants to merge 12 commits into
base: ete3
Choose a base branch
from
Open

Conversation

NikiB
Copy link

@NikiB NikiB commented Dec 6, 2017

The function gives the option to add full y axis scale to the tree in linear or log setting.
Also deleted the the twice written add_legend function in qt4_render.py (left one copy)
and set the script to fit better the pep8 structure

@jhcepas
Copy link
Member

jhcepas commented Dec 7, 2017

that's great. Thanks! I would review as soon as possible.
How does the y-axis scale look like? is the tree expected to rotate so the y-axis follows branch lengths? Maybe easier to understand if you can add a screenshot. I can not try the code right now..

@NikiB
Copy link
Author

NikiB commented Dec 7, 2017

The scale rotates but only at 90/180/270 degrees (It looks graphically bad otherwise)
I'll add my basic code here and a screenshot.

@NikiB
Copy link
Author

NikiB commented Dec 7, 2017

import os
import math
import matplotlib.pyplot as plt

%matplotlib notebook

os.environ["DISPLAY"] = ':4'
import ete3

t_f= '(((Leaf 32:1,Leaf 31:1):0.5,(Leaf 22:1,Leaf 21:1):11,(Leaf 2:1,Leaf 1:1):11,(Leaf 3:1,Leaf 4:1):12):11,(Leaf 5:1,Leaf 6:1):24);'
t_r = ete3.Tree(newick=t_f, format=1)

tss = ete3.TreeStyle()
tss.show_scale = False

t1 = ete3.TextFace("Header Face", fsize=12, fgcolor='black')
t2 = ete3.TextFace("Footer Face", fsize=8, fgcolor='black')
tss.title.add_face(ete3.TextFace('tree_name', fsize=20), column=0)
tss.aligned_header.add_face(t1,0)

tss.aligned_foot.add_face(t2, column=-1)

for leaf in t_r:
leaf.add_face(ete3.TextFace('text1'), column=1, position='aligned')
leaf.add_face(ete3.TextFace('text2'), column=2, position='aligned')

tss.show_scale=True

tss.rotation = 90

tss.y_axis['scale_length'] = math.ceil(t_r.get_farthest_leaf()[1] - t_r.dist)
tss.y_axis['show'] = True

tss.y_axis['scale_type'] = 'log'

t_r.render("%%inline", tree_style=tss)
tree_1
tree_2

@jhcepas
Copy link
Member

jhcepas commented Dec 7, 2017

awesome, this is actually addressing #112
Note that when using this type of scale, node.img_style["size"] should be set to 0 in all internal nodes, otherwise tree length and the scale bar will not fit and align perfectly.

@NikiB
Copy link
Author

NikiB commented Dec 7, 2017

yes, various node sizes will alter the results

@NikiB NikiB force-pushed the scale_y_axis branch 8 times, most recently from 5565957 to 27c2a99 Compare January 16, 2018 08:42
@NikiB NikiB force-pushed the scale_y_axis branch 2 times, most recently from 7813a26 to 6edd122 Compare January 23, 2018 12:53
@NikiB
Copy link
Author

NikiB commented Jan 24, 2018

Hi, I added a function that resize the internal nodes to node.img_style["size"]=0 and adds a face the floats behind the nodes and doesn't alter the scale.

@NikiB
Copy link
Author

NikiB commented May 1, 2018

Hi,
We have fixed qt_render to match qt5 and qt4 simultaneously and updated with the latest master.

@jhcepas
Copy link
Member

jhcepas commented May 4, 2018

thanks! I will need some time for testing. Could you add some test code in ete/ete3/test/test_treeview/test_all_treeview.py. It is not the most elegant way of testing the rendering, but at least allows to check at a glance that graphic features are working ok...

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

Successfully merging this pull request may close these issues.

None yet

3 participants