Issue
I want to add some modifications to my force plot (created by shap.plots.force
) using Matplotlib, e.g. adding title, using tight layout etc. However, I tried to add title and the title doesn't show up. Any ideas why and how can I add the title using Matplotlib?
import numpy as np
import shap
import matplotlib.pyplot as plt
myBaseline=1.5
shap_values_0 = np.array([-1, -4, 3])
test_point_0 = np.array([11, 12, 13])
features_names = ['a1','a2','a3']
shap.plots.force(myBaseline,shap_values_0,test_point_0,features_names,matplotlib = 1)
plt.suptitle("This is my title") # It doesn't show up, why?
fig = plt.gcf()
fig.canvas.draw()
plt.close()
Solution
The last lines in force_plot
are:
if show:
plt.show()
else:
return plt.gcf()
so, if you set show = False
you can get prepared SHAP plot as figure
object and customize it to your needs as usual:
import shap
myBaseline = 1.5
shap_values_0 = np.array([-1, -4, 3])
test_point_0 = np.array([11, 12, 13])
features_names = ["a1", "a2", "a3"]
shap.plots.force(
myBaseline, shap_values_0, test_point_0, features_names, matplotlib=True, show=False
)
plt.title("This is my title", y=1.75)
plt.show()
Answered By - Sergey Bushmanov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.