-1

I have the following situation: I'm using the shap library in Python to make a chart. Here's the code I'm using:

shap.summary_plot(shap_values[1], df, plot_type="bar")

The chart is printed in my Jupyter Notebook, but if I try to save this plot as an image, I get this error:

AttributeError: 'NoneType' object has no attribute 'savefig'

I understand this function only prints the plot in my Jupyter Notebook, but is actually returning a DataFrame.

So how can I access the plot directly to save the plot as an image, given that I don't have access to the function itself?

leo_val
  • 150
  • 8
  • 1
    Where is the code that uses `savefig`? – mkrieger1 Jul 20 '23 at 19:57
  • It's simply the above shap.summary_plot(shap_values[1], df, plot_type="bar").savefig('path_to_file'), as usual in matplotlib – leo_val Jul 20 '23 at 20:04
  • 1
    Well, the usual way in matplotlib is calling `plt.savefig('filename.png')`. That saves "the current figure". You should call it inside the same cell as where the plot was created. Matplotlib isn't suited to create a chain of calls (unlike e.g. pandas). – JohanC Jul 20 '23 at 20:16

1 Answers1

1

This issue was already addressed in the GitHub repo of Shap, here is the solution https://github.com/shap/shap/issues/153