However, when trying to launch the app, it raises an attribute error:
AttributeError: ‘AxesSubplot’ object has no attribute ‘savefig’
I also already experimented with adding an ax argument as has been done here, but it doesn’t quite solve the case for me.
Thank you in advance!
Steps to reproduce
Code snippet:
# Import packages
import numpy as np
import pandas as pd
import streamlit as st
from xgboost import XGBClassifier, plot_importance
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
...
# Plot the most important features
fig = plot_importance(model)
st.pyplot(fig)
Expected behavior:
I expect the plot to be displayed within the app page.
Actual behavior:
An attribute error is raised:
AttributeError: ‘AxesSubplot’ object has no attribute ‘savefig’
Edit: i also tried solving the problem via the following code.
# Plot the most important features
plot_importance(model)
fig = pyplot.show()
st.pyplot(fig)
In that case, the plot is generally displayed but I receive the usual PyplotGlobalUseWarning:
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.
To future-proof this code, you should pass in a figure as shown below …
Thank you a thousand times Snehan, this is the solution! Afrer adding the .figure attribute, the app displays the plot without any warning or error. Thank you!