-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
plot_tree diagram is cropped in iris example #21908
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
Comments
Is a |
Nope, the png is still cropped. |
Quick and dirty reproducer: # %%
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier, plot_tree
# Load data
iris = load_iris()
plt.figure()
clf = DecisionTreeClassifier().fit(iris.data, iris.target)
plot_tree(clf, filled=True)
plt.savefig('/tmp/tree.png')
# %%
from matplotlib.image import imread
plt.figure()
plt.imshow(imread('/tmp/tree.png')) |
Seems like a regression in 1.0, the png is fine with scikit-learn 0.24.2 and keeping the same matplotlib version (3.4.2 for completeness). |
I have two candidates PRs for introducing the regression:
Otherwise we did not change anything that should impact the tree plotting |
Seems to be culprit #20023. I looked a bit at the code but this looks a bit too much for my matplotlib skills, maybe @thomasjpfan has some insights into this? |
#20023 is the issue. Reverting it would also lead to another regression. I'm looking into a fix. |
Can resizing the image when it's opened by imread() solve the issue? |
That would not resolve the issue because the saved image itself is drawn incorrectly. One can test this out by running: import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier, plot_tree
# Load data
iris = load_iris()
plt.figure()
clf = DecisionTreeClassifier().fit(iris.data, iris.target)
plot_tree(clf, filled=True)
plt.savefig('tree.png') and open I opened #21917 to resolve this issue. |
https://scikit-learn.org/stable/auto_examples/tree/plot_iris_dtc.html
Note: I tried fixing it quickly by playing with the figsize to no avail. Looks like you can see the full diagram on the matplotlib figure but the diagram is cropped when saving to a png.
Looks like it was working fine in 0.24 (maybe a regression or maybe some changes in matplotlib hard to tell ...):
https://scikit-learn.org/0.24/auto_examples/tree/plot_iris_dtc.html
The text was updated successfully, but these errors were encountered: