Ralph
Ralph

Reputation: 5

My code seems not to be printing nothing on streamlit but it works good on jupiter

Here is my code:

def month_year(d):
    m, y = d
    months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    return months[m - 1] + '-' + str(y % 100)


    ax2 = new_df['Average_Answer_Speed'].plot(kind='bar', stacked=True, figsize=(15,10))
    plt.xticks(rotation = 45)
    ax2.set_title('Average Call Answer Speed in Seconds', fontsize = 18, fontweight = "bold")
    ax2.set_xlabel('')
    for p in ax2.patches:
        ax2.annotate(f'{int(round(p.get_height()))}', (p.get_x() + p.get_width() / 2., p.get_height() / 2), ha='center', va='center', xytext=(0, 10), textcoords='offset points', color='white')
    plt.show()

Do I need to use something else instead of plt show ? so it work on streamlit?

Upvotes: 0

Views: 232

Answers (1)

Jamiu S.
Jamiu S.

Reputation: 5741

plt.show() will show output on a different window, use st.write(ax2) instead

import streamlit as st

ax2 = new_df['Average_Answer_Speed'].plot(kind='bar', stacked=True, figsize=(15,10))
plt.xticks(rotation = 45)
ax2.set_title('Average Call Answer Speed in Seconds', fontsize = 18, fontweight = "bold")
ax2.set_xlabel('')
for p in ax2.patches:
    ax2.annotate(f'{int(round(p.get_height()))}', (p.get_x() + p.get_width() / 2., p.get_height() / 2), ha='center', va='center', xytext=(0, 10), textcoords='offset points', color='white')
st.write(ax2)
# plt.show()

Upvotes: 1

Related Questions