我在django和ete3工具箱编程中是个新手。
我想在views.py中使用ete3工具包生成系统树,并将树的svg图像渲染为模板。
当我尝试如下所示时
matrix = """
#Names\tcol1\tcol2\tcol3\tcol4\tcol5\tcol6\tcol7
A\t-1.23\t-0.81\t1.79\t0.78\t-0.42\t-0.69\t0.58
B\t-1.76\t-0.94\t1.16\t0.36\t0.41\t-0.35\t1.12
C\t-2.19\t0.13\t0.65\t-0.51\t0.52\t1.04\t0.36
D\t-1.22\t-0.98\t0.79\t-0.76\t-0.29\t1.54\t0.93
E\t-1.47\t-0.83\t0.85\t0.07\t-0.81\t1.53\t0.65
F\t-1.04\t-1.11\t0.87\t-0.14\t-0.80\t1.74\t0.48
G\t-1.57\t-1.17\t1.29\t0.23\t-0.20\t1.17\t0.26
H\t-1.53\t-1.25\t0.59\t-0.30\t0.32\t1.41\t0.77
"""
header = 'col1\tcol2\tcol3\tcol4\tcol5\tcol6\tcol7'.split('\t')
t = ClusterTree("(((A,B),(C,(D,E))),(F,(G,H)));",text_array=matrix)
tree_style = TreeStyle()
setup_heatmap(t, tree_style, header)
tree_style.show_scale = False
tree_style.show_leaf_name = True
tree_style.draw_guiding_lines=True
context['svg'] = t.render('tree_2.svg', tree_style=tree_style)
return render(self.request, self.template_name, context)
<div> {{svg|safe}} </div>
然后我得到了这个字典组成的字符串
{'nodes': [], 'faces': [[181.0, 30.5, 190.0, 45.5, 3, 'A'], [191.5, 27.5, 212.5, 48.5, 3, None], [211.5, 27.5, 232.5, 48.5, 3, None], [231.5, 27.5, 252.5, 48.5, 3, None], [251.5, 27.5, 272.5, 48.5, 3, None], [271.5, 27.5, 292.5, 48.5, 3, None], [291.5, 27.5, 312.5, 48.5, 3, None], [311.5, 27.5, 332.5, 48.5, 3, None], [181.0, 50.5, 190.0, 65.5, 4, 'B'], [191.5, 47.5, 212.5, 68.5, 4, None], [211.5, 47.5, 232.5, 68.5, 4, None], [231.5, 47.5, 252.5, 68.5, 4, None], [251.5, 47.5, 272.5, 68.5, 4, None], [271.5, 47.5, 292.5, 68.5, 4, None], [291.5, 47.5, 312.5, 68.5, 4, None], [311.5, 47.5, 332.5, 68.5, 4, None], [181.0, 70.5, 191.0, 85.5, 6, 'C'], [191.5, 67.5, 212.5, 88.5, 6, None], [211.5, 67.5, 232.5, 88.5, 6, None], [231.5, 67.5, 252.5, 88.5, 6, None], [251.5, 67.5, 272.5, 88.5, 6, None], [271.5, 67.5, 292.5, 88.5, 6, None], [291.5, 67.5, 312.5, 88.5, 6, None], [311.5, 67.5, 332.5, 88.5, 6, None], [181.0, 90.5, 191.0, 105.5, 8, 'D'], [191.5, 87.5, 212.5, 108.5, 8, None], [211.5, 87.5, 232.5, 108.5, 8, None], [231.5, 87.5, 252.5, 108.5, 8, None], [251.5, 87.5, 272.5, 108.5, 8, None], [271.5, 87.5, 292.5, 108.5, 8, None], [291.5, 87.5, 312.5, 108.5, 8, None], [311.5, 87.5, 332.5, 108.5, 8, None], [181.0, 110.5, 190.0, 125.5, 9, 'E'], [191.5, 107.5, 212.5, 128.5, 9, None], [211.5, 107.5, 232.5, 128.5, 9, None], [231.5, 107.5, 252.5, 128.5, 9, None], [251.5, 107.5, 272.5, 128.5, 9, None], [271.5, 107.5, 292.5, 128.5, 9, None], [291.5, 107.5, 312.5, 128.5, 9, None], [311.5, 107.5, 332.5, 128.5, 9, None], [181.0, 130.5, 189.0, 145.5, 11, 'F'], [191.5, 127.5, 212.5, 148.5, 11, None], [211.5, 127.5, 232.5, 148.5, 11, None], [231.5, 127.5, 252.5, 148.5, 11, None], [251.5, 127.5, 272.5, 148.5, 11, None], [271.5, 127.5, 292.5, 148.5, 11, None], [291.5, 127.5, 312.5, 148.5, 11, None], [311.5, 127.5, 332.5, 148.5, 11, None], [181.0, 150.5, 192.0, 165.5, 13, 'G'], [191.5, 147.5, 212.5, 168.5, 13, None], [211.5, 147.5, 232.5, 168.5, 13, None], [231.5, 147.5, 252.5, 168.5, 13, None], [251.5, 147.5, 272.5, 168.5, 13, None], [271.5, 147.5, 292.5, 168.5, 13, None], [291.5, 147.5, 312.5, 168.5, 13, None], [311.5, 147.5, 332.5, 168.5, 13, None], [181.0, 170.5, 191.0, 185.5, 14, 'H'], [191.5, 167.5, 212.5, 188.5, 14, None], [211.5, 167.5, 232.5, 188.5, 14, None], [231.5, 167.5, 252.5, 188.5, 14, None], [251.5, 167.5, 272.5, 188.5, 14, None], [271.5, 167.5, 292.5, 188.5, 14, None], [291.5, 167.5, 312.5, 188.5, 14, None], [311.5, 167.5, 332.5, 188.5, 14, None]], 'node_areas': {0: [1.0, 28.0, 192.0, 188.0], 1: [1.0, 28.0, 191.0, 128.0], 2: [46.0, 28.0, 190.0, 68.0], 3: [113.5, 28.0, 190.0, 48.0], 4: [113.5, 48.0, 190.0, 68.0], 5: [46.0, 68.0, 191.0, 128.0], 6: [91.0, 68.0, 191.0, 88.0], 7: [91.0, 88.0, 191.0, 128.0], 8: [136.0, 88.0, 191.0, 108.0], 9: [136.0, 108.0, 190.0, 128.0], 10: [1.0, 128.0, 192.0, 188.0], 11: [61.0, 128.0, 189.0, 148.0], 12: [61.0, 148.0, 192.0, 188.0], 13: [121.0, 148.0, 192.0, 168.0], 14: [121.0, 168.0, 191.0, 188.0]}}
有什么方法可以在不存储的情况下渲染树的svg?