Using pyplot with sklearn, PyplotGlobalUseWarning warning

Hi,

I’m trying to show some sklearn plots on streamlit and running up against the deprecation error calling pyplot with no arguments:

        RocCurveDisplay.from_estimator(model, x_test, y_test)
        st.pyplot()
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.

These plots seem to be a different structure from matplotlib, if I try the suggested fix, I get an error:

        fig_ROC, ax = RocCurveDisplay.from_estimator(model, x_test, y_test)
        st.pyplot(fig_ROC)
TypeError: cannot unpack non-iterable RocCurveDisplay object

I know I can switch the warning off, but what’s the long term solution for this?

Thanks!

The answer is in the .figure_ attribute:

        fig_roc = RocCurveDisplay.from_estimator(model, x_test, y_test)
        st.pyplot(fig_roc.figure_)
1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.