2

我一直在研究一个包装器ete3,我可以在其中自定义叶标签(即显示哪些叶标签)和节点存在(即显示哪些叶节点)。我遇到的一个问题是定义标签大小。

当我尝试更改fsizein 时TextFace,并没有真正发生 :( 我遇到了一个奇怪的怪癖,其中的标签很大,而树真的很小。

我无法获得实际树状图的比例和标签一起工作以获得一个有凝聚力的数字。

这是一个无法更改iris数据集上的标签大小的示例 下面附上 3 种不同的标签大小:1, 1e2, and 1e4

import pandas as pd
from sklearn.datasets import load_iris
import ete3

# Get data
X = pd.DataFrame(load_iris().data, columns=[load_iris().feature_names], index=["iris_%d"%_ for _ in range(150)])
DF_dism = 1 - X.T.corr()
# outside program to create newick tree
tree_str = '(((((((((((iris_105:0.015466,iris_104:0.015466):0.002489,iris_128:0.017954):0.051900,iris_134:0.069854):0.014699,iris_106:0.084554):0.029907,((((iris_113:0.008951,iris_108:0.008951):0.007140,iris_114:0.016091):0.020324,iris_132:0.036415):0.015510,iris_122:0.051925):0.062536):0.154083,iris_100:0.268544):0.059595,((((iris_143:0.029031,iris_130:0.029031):0.035661,iris_121:0.064692):0.035647,((((iris_142:0.000000,iris_101:0.000000):0.010308,iris_107:0.010308):0.023017,iris_119:0.033325):0.027399,iris_103:0.060724):0.039616):0.060280,(((((iris_111:0.010695,iris_102:0.010695):0.004910,iris_140:0.015606):0.019544,iris_144:0.035150):0.021438,(iris_146:0.026679,iris_135:0.026679):0.029909):0.013635,iris_136:0.070223):0.090396):0.167519):0.152880,((((((iris_137:0.036573,iris_117:0.036573):0.005650,(iris_116:0.021554,iris_109:0.021554):0.020669):0.014556,((iris_125:0.016457,iris_124:0.016457):0.013361,(iris_149:0.013347,iris_148:0.013347):0.016472):0.026961):0.015363,(iris_120:0.052702,iris_112:0.052702):0.019440):0.019892,iris_83:0.092034):0.090205,(((((iris_147:0.019669,iris_123:0.019669):0.025376,iris_139:0.045045):0.004471,iris_133:0.049517):0.038807,(iris_145:0.046706,iris_68:0.046706):0.041617):0.003435,((iris_129:0.034158,iris_72:0.034158):0.018834,iris_115:0.052993):0.038766):0.090480):0.298780):0.446896,iris_118:0.927915):0.171235,(((((((((iris_89:0.019602,iris_78:0.019602):0.012196,iris_94:0.031798):0.021078,(iris_62:0.024576,iris_54:0.024576):0.028300):0.019265,(iris_76:0.021066,iris_60:0.021066):0.051074):0.033419,(iris_91:0.061458,iris_52:0.061458):0.044101):0.073034,((((((iris_73:0.015746,iris_55:0.015746):0.007907,iris_70:0.023653):0.017085,iris_63:0.040738):0.033484,(iris_77:0.026480,iris_53:0.026480):0.047742):0.021259,iris_84:0.095481):0.008300,iris_66:0.103781):0.074812):0.095629,((((iris_131:0.025100,iris_127:0.025100):0.033935,iris_126:0.059035):0.040224,((iris_138:0.040319,iris_110:0.040319):0.005869,iris_90:0.046188):0.053071):0.017816,(iris_141:0.074887,iris_87:0.074887):0.042187):0.157148):0.215498,(((((iris_93:0.013769,iris_71:0.013769):0.008009,iris_65:0.021777):0.053482,iris_57:0.075259):0.036176,(((iris_88:0.024950,iris_85:0.024950):0.038041,iris_95:0.062991):0.011447,((((iris_75:0.013694,iris_50:0.013694):0.013866,iris_51:0.027560):0.005357,iris_82:0.032917):0.006739,(iris_74:0.022758,iris_61:0.022758):0.016898):0.034782):0.036997):0.085015,((((iris_99:0.015603,iris_67:0.015603):0.011335,(iris_96:0.010209,iris_56:0.010209):0.016730):0.031396,(iris_97:0.016052,iris_81:0.016052):0.042283):0.030065,(((iris_80:0.014517,iris_58:0.014517):0.019641,iris_59:0.034158):0.018663,((iris_92:0.016236,iris_86:0.016236):0.008542,iris_69:0.024778):0.028044):0.035579):0.108050):0.293270):0.285865,((iris_79:0.123616,iris_64:0.123616):0.124095,iris_98:0.247711):0.527874):0.323564):2.691791,((((iris_41:0.252019,iris_25:0.252019):0.163686,(((((iris_29:0.022655,iris_8:0.022655):0.021997,iris_3:0.044652):0.003728,iris_45:0.048380):0.042574,((iris_12:0.021454,iris_1:0.021454):0.024231,iris_23:0.045685):0.045269):0.048283,(((iris_30:0.015235,iris_20:0.015235):0.026412,((iris_34:0.000000,iris_9:0.000000):0.000000,iris_37:0.000000):0.041647):0.030817,iris_24:0.072463):0.066774):0.276467):0.140239,((((((((iris_39:0.009341,iris_18:0.009341):0.008969,iris_26:0.018311):0.020329,iris_11:0.038639):0.016404,((iris_28:0.016981,iris_27:0.016981):0.013305,(iris_49:0.016905,iris_7:0.016905):0.013381):0.024757):0.022419,iris_31:0.077462):0.013526,((iris_47:0.027609,iris_38:0.027609):0.019907,iris_44:0.047516):0.043472):0.107130,(((iris_17:0.027138,iris_5:0.027138):0.025207,((iris_48:0.018085,iris_0:0.018085):0.007010,iris_43:0.025096):0.027249):0.032517,((iris_36:0.008628,iris_35:0.008628):0.032997,(iris_10:0.006140,iris_2:0.006140):0.035485):0.043237):0.113256):0.120936,((((iris_40:0.016634,iris_21:0.016634):0.014411,iris_6:0.031045):0.046044,iris_19:0.077089):0.029864,(((iris_42:0.018855,iris_13:0.018855):0.014108,iris_46:0.032962):0.011022,iris_4:0.043984):0.062968):0.212102):0.236889):0.303087,(((((iris_33:0.060688,iris_16:0.060688):0.035284,iris_32:0.095972):0.034956,iris_14:0.130928):0.063009,iris_15:0.193936):0.224991,iris_22:0.418928):0.440103):2.931910);'
# ete3 tree
tree = ete3.Tree(tree_str)
# Annotate tree
node_size = 10
label_size = 10000
for node in tree.traverse():
    if node.is_leaf():
        node.img_style["size"] = node_size

        # Show leaf labels
        name_face = ete3.TextFace(node.name, fgcolor="black", fsize=label_size)
        node.add_face(name_face, column=0, position='branch-right')

# Circular Style
ts = ete3.TreeStyle()
ts.show_branch_length = True # show branch length
ts.show_scale = True
ts.mode = "c" # "c" is circular mode
ts.show_leaf_name = False
ts.show_scale = False
tree.render("%%inline", dpi=300, tree_style=ts, w=500)

在此处输入图像描述

当标签较长时,我不确定如何将标签大小更改为树大小比率。例如,下面: 在此处输入图像描述

4

0 回答 0