8000 Export_graphviz() defaults "Helvetica" font by wstates · Pull Request #14290 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Export_graphviz() defaults "Helvetica" font #14290

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

Closed
wants to merge 11 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions sklearn/tree/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def __init__(self, max_depth=None, feature_names=None,
class_names=None, label='all', filled=False,
impurity=True, node_ids=False,
proportion=False, rotate=False, rounded=False,
precision=3, fontsize=None):
precision=3, fontsize=None, fontname='helvetica'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add it to the docstring above

self.max_depth = max_depth
self.feature_names = feature_names
self.class_names = class_names
Expand All @@ -196,6 +196,7 @@ def __init__(self, max_depth=None, feature_names=None,
self.rounded = rounded
self.precision = precision
self.fontsize = fontsize
self.fontname = fontname

def get_color(self, value):
# Find the appropriate color & intensity for a node
Expand Down Expand Up @@ -355,15 +356,15 @@ def __init__(self, out_file=SENTINEL, max_depth=None,
feature_names=None, class_names=None, label='all',
filled=False, leaves_parallel=False, impurity=True,
node_ids=False, proportion=False, rotate=False, rounded=False,
special_characters=False, precision=3):
special_characters=False, precision=3, fontname='helvetica'):

super().__init__(
max_depth=max_depth, feature_names=feature_names,
class_names=class_names, label=label, filled=filled,
impurity=impurity,
node_ids=node_ids, proportion=proportion, rotate=rotate,
rounded=rounded,
precision=precision)
precision=precision, fontname=fontname)
self.leaves_parallel = leaves_parallel
self.out_file = out_file
self.special_characters = special_characters
Expand Down Expand Up @@ -434,15 +435,15 @@ def head(self):
', style="%s", color="black"'
% ", ".join(rounded_filled))
if self.rounded:
self.out_file.write(', fontname=helvetica')
self.out_file.write(', fontname=%s' % self.fontname)
self.out_file.write('] ;\n')

# Specify graph & edge aesthetics
if self.leaves_parallel:
self.out_file.write(
'graph [ranksep=equally, splines=polyline] ;\n')
if self.rounded:
self.out_file.write('edge [fontname=helvetica] ;\n')
self.out_file.write('edge [fontname=%s] ;\n' % self.fontname)
if self.rotate:
self.out_file.write('rankdir=LR ;\n')

Expand Down Expand Up @@ -656,7 +657,8 @@ def export_graphviz(decision_tree, out_file=None, max_depth=None,
feature_names=None, class_names=None, label='all',
filled=False, leaves_parallel=False, impurity=True,
node_ids=False, proportion=False, rotate=False,
rounded=False, special_characters=False, precision=3):
rounded=False, special_characters=False, precision=3,
fontname='helvetica'):
"""Export a decision tree in DOT format.

This function generates a GraphViz representation of the decision tree,
Expand Down Expand Up @@ -733,6 +735,9 @@ def export_graphviz(decision_tree, out_file=None, max_depth=None,
Number of digits of precision for floating point in the values of
impurity, threshold and value attributes of each node.

fontname : str,optional (default='helvetica')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fontname : str,optional (default='helvetica')
fontname : str, optional (default='helvetica')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wstates could you accept this suggestion

Set output dot file font. if there is a font error, try using "sans"

Returns
-------
dot_data : string
Expand Down Expand Up @@ -772,7 +777,7 @@ def export_graphviz(decision_tree, out_file=None, max_depth=None,
filled=filled, leaves_parallel=leaves_parallel, impurity=impurity,
node_ids=node_ids, proportion=proportion, rotate=rotate,
rounded=rounded, special_characters=special_characters,
precision=precision)
precision=precision, fontname=fontname)
exporter.export(decision_tree)

if return_string:
Expand Down
0