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!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.