xgb.plot_tree font size python

%matplotlib inline
from xgboost import plot_tree
from matplotlib.pylab import rcParams

##set up the parameters
rcParams['figure.figsize'] = 80,50

plot_tree(finalmodel, num_trees=X)

hope this will help, I think you should set up the matplotlib parameters first.


I created this helper function to export xgboost trees in high resolution:

def plot_tree(xgb_model, filename, rankdir='UT'):
    """
    Plot the tree in high resolution
    :param xgb_model: xgboost trained model
    :param filename: the pdf file where this is saved
    :param rankdir: direction of the tree: default Top-Down (UT), accepts:'LR' for left-to-right tree
    :return:
    """
    import xgboost as xgb
    import os
    gvz = xgb.to_graphviz(xgb_model, num_trees=xgb_model.best_iteration, rankdir=rankdir)
    _, file_extension = os.path.splitext(filename)
    format = file_extension.strip('.').lower()
    data = gvz.pipe(format=format)
    full_filename = filename
    with open(full_filename, 'wb') as f:
        f.write(data)

You can give it a try with the following calls. I prefer the 'pdf' version as it provides vector images in which you can zoom in to infinity.

plot_tree(xgb_model, 'xgboost_test_tree.pdf')
plot_tree(xgb_model, 'xgboost_test_tree.png')
plot_tree(xgb_model, 'xgboost_test_tree_LR.pdf', 'LR')
plot_tree(xgb_model, 'xgboost_test_tree_LR.png', 'LR')