Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

224
Visualizações
Shap - The color bar is not displayed in the summary plot

When displaying summary_plot, the color bar does not show.

shap.summary_plot(shap_values, X_train)

Summary plot

I have tried changing plot_size. When the plot is higher the color bar appears, but it is very small - doesn't look like it should.

shap.summary_plot(shap_values, X_train, plot_size=0.7)

Higher summary plot

Here is an example of a proper looking color bar. Proper summary plot

Does anyone know if this can be fixed somehow?

How to reproduce:

import pandas as pd
import shap
import sklearn
from sklearn.ensemble import RandomForestRegressor

# a classic housing price dataset
X,y = shap.datasets.boston()

# a simple linear model
model = RandomForestRegressor(max_depth=6, random_state=0, n_estimators=10)
model.fit(X, y)
shap_values = shap.TreeExplainer(model).shap_values(X)
shap.summary_plot(shap_values, X)

In this case, the color bar is displayed, but it is very small. I have chosen such an example to make it easy to retrieve the data.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

I had the same problem as you did, and I found that the solution was to downgrade matplotlib to 3.4.3.. It appears SHAP isn't optimized for matplotlib 3.5.1 yet.

over 4 years ago · Santiago Trujillo Relatório

0

I had a similar issue and I was using max_display=10. The below code solved my problem:

plt.gcf().axes[-1].set_aspect(100)
plt.gcf().axes[-1].set_box_aspect(100)
over 4 years ago · Santiago Trujillo Relatório

0

As mentioned above, it seems that the handling of colorbar or box aspect ratio has been changed in matplotlib.pyplot version 3.5. However, you can correct that.

  • Use shap.summary_plot(..., show=False) to allow altering the plot
  • As mentioned above, set the aspect of the colorbar with plt.gcf().axes[-1].set_aspect(1000)
  • Then set also the aspect of the color bar's box plt.gcf().axes[-1].set_box_aspect(1000)

This gives you the old result back. If you want to make the colorbar thicker, set the aspect to 100.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda