Skip to content
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

boston-house-ml-app.py - PyplotGlobalUseWarning: You are calling st.pyplot() without any arguments. #14

Open
datalifenyc opened this issue Mar 6, 2022 · 1 comment

Comments

@datalifenyc
Copy link

datalifenyc commented Mar 6, 2022

When plotting the 2 SHAP figures, the figures appear, but the following warning also appears.

st.header('Feature Importance')
plt.title('Feature importance based on SHAP values')
shap.summary_plot(shap_values, X)
st.pyplot(bbox_inches = 'tight')
st.write('----')

plt.title('Feature importance based on SHAP values (Bar)')
shap.summary_plot(shap_values, X, plot_type = 'bar')
st.pyplot(bbox_inches = 'tight')

PyplotGlobalUseWarning: You are calling st.pyplot() without any arguments. After December 1st, 2020, we will remove the ability to do this as it requires the use of Matplotlib's global figure object, which is not thread-safe.

The temporary solution is to configure the streamlit option:

st.set_option('deprecation.showPyplotGlobalUse', False)

However, is there a solution that does not require disabling deprecation warnings?

For some of the prior examples, like the basketball_app.py, it was easy to determine what to pass as the fig:

st.pyplot(f)

For this streamlit dashboard, which incorporates the SHAP library, what can be passed in as the <fig> in line 81 & 86: st.pyplot(<fig?>, bbox_inches = 'tight')?

Version Reference:
python - 3.10.0
matplotlib - 3.5.1
streamlit - 1.5.1
scikit-learn - 1.0.2
shap - 0.39.0

@cyrbaufr
Copy link

cyrbaufr commented Jun 5, 2022

Correct you need to add fig st.pyplot(fig, bbox_inches='tight') with fig, ax = plt.subplots(figsize=(15,5)). Further details here https://discuss.streamlit.io/t/pyplotglobalusewarning/6578/5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants