You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use the SVG file coming out of the DTreeViz Render, but the bounding box around it is huge, and when I embed it into html code the tree becomes tiny.
how can I get a tight bounding box around the SVG file?
Example
#!/usr/bin/env python# Imports# -------importosimportdtreevizfrompathlibimportPathfromtempfileimportNamedTemporaryFilefromsklearn.treeimportDecisionTreeClassifierfromsklearn.datasetsimportmake_blobs# Create temp files# -----------------tempfile=Path(NamedTemporaryFile().name)
svg_temp=tempfile.with_suffix('.svg')
html_temp=tempfile.with_suffix('.html')
print(f"You can delete this files later:\n{svg_temp}\n{html_temp}")
# Create example decision tree# ----------------------------X, y=make_blobs(n_samples=10, n_features=2, centers=3)
d=DecisionTreeClassifier()
d.fit(X, y)
# Export Decision Tree to SVG# ---------------------------tree_model=dtreeviz.model(d, X_train=X, y_train=y)
tree_render=tree_model.view()
tree_render.save(str(svg_temp))
# Create a HTML for displaying the SVG# ------------------------------------html=f"""<!doctype html><html><head><style>body {{margin: auto;max-width: 42em;}}</style></head><body><img src="{svg_temp}"/></body>"""withopen(html_temp, 'w') asfid:
fid.write(html)
# Show whats the issue# --------------------# Expected Behavior: Graphic should be full size# Experienced Behavior: A small tree is displayed in the upper left corner of the browser.os.system('start '+str(svg_temp))
# Experienced Behavior: Small tree fills only left side.# Expected Behavior: An image of the tree fills out the complete width.os.system('start '+str(html_temp))
The text was updated successfully, but these errors were encountered:
Hey there,
I want to use the SVG file coming out of the DTreeViz Render, but the bounding box around it is huge, and when I embed it into html code the tree becomes tiny.
dtreeviz/dtreeviz/utils.py
Line 269 in 0a84c38
how can I get a tight bounding box around the SVG file?
Example
The text was updated successfully, but these errors were encountered: