St.pyplot displaying something different to ide

Hello,

I am trying to create a dashboard for my team at work, but for some reason my plot is doing something unexpected when displayed in the app. The code I am using to create the graph is here:

temp = df[‘Month’].value_counts().reset_index()
months = [‘April’,‘May’,‘June’,‘July’,‘August’,
‘September’,‘October’,‘November’,
‘December’,‘January’,‘February’,‘March’]
temp[‘Month’] = pd.CategoricalIndex(temp[‘Month’], ordered=True, categories=months)
temp=temp.sort_values(‘Month’)
fig, ax = plt.subplots(figsize=(8,4))
plt.barh(temp[‘Month’], temp[‘count’], color = ‘#64A70B’)
ax.set_title(f’Sots Issued: {“,”.join(year)}', fontsize=16, fontweight=‘bold’)
#add data labels
for bar in ax.patches:
ax.text(
# Put the text in the middle of each bar. get_x returns the start
# so we add half the width to get to the middle.
bar.get_x() + bar.get_width() / 2,
# Vertically, add the height of the bar to the start of the bar,
bar.get_height()/2.4 + bar.get_y(),
# This is actual value we’ll show.
round(bar.get_width()),
# Center the labels and style them a bit.
ha=‘center’,
weight=‘bold’,
size=8
)

        plt.tick_params(left=False, bottom=False)
        ax.spines['top'].set_visible(False)
        ax.spines['right'].set_visible(False)
        ax.spines['bottom'].set_visible(False)
        ax.spines['left'].set_visible(False)
        st.pyplot(fig)

inside of spyder I get this:
image

but in streamlit it contains extra months which I don’t want:

does anyone know why this may be?

I cannot reproduce this. I don’t get the extra months when using my own data.

For some reason when I assigned my counts with the temp variable, when adding an extra category to count, then it works as expected. So I believe it was just keeping all months whether or not it had a value associated in the given year. Thank you for your effort in replicating it though!

Thanks