0

I have a legend with far too many values, i have implemented a scroll function however i cannot figure out how to properly size my chart and legend

This is what i have, and when i run this just on my computer not pushing to streamlit the scroll bar works but this displays the entire legend on streamlit everytime i try to change the size i continue with similar outputs. This is an image of my webpage right now, as you can see the legend continues down the page, i need to make it cut off so i can use the scroll function:

fig1 = plt.figure(figsize=(7, 3))
axx = fig.add_axes([0.1, 0.6, 0.3, 0.3])
p1 = volcanos["Country"].value_counts()

fig1, axx = plt.subplots()
axx.pie(p1, labels=p1.keys(), autopct='%1.1f%%',
                    shadow=True, startangle=90)
legend = axx.legend(loc="upper left", bbox_to_anchor=(1.02, 0, 0.07, 1))

# pixels to scroll per mousewheel event
d = {"down" : 30, "up" : -30}
def func(evt):
    if legend.contains(evt):
        bbox = legend.get_bbox_to_anchor()
        bbox = Bbox.from_bounds(bbox.x0, bbox.y0+d[evt.button], bbox.width, bbox.height)
        tr = legend.axes.transAxes.inverted()
        legend.set_bbox_to_anchor(bbox.transformed(tr))
        fig1.canvas.draw_idle()

fig1.canvas.mpl_connect("scroll_event", func)

st.pyplot(fig1)
vvvvv
  • 25,404
  • 19
  • 49
  • 81
  • Have you read this thread? https://stackoverflow.com/questions/60838623/limiting-the-size-of-legend-in-matplotlib-in-python-then-allowing-scrolling-wit – Caroline Frasca Dec 22 '22 at 15:31
  • (Also worth noting that this is controlled by pyplot rather than Streamlit) – Caroline Frasca Dec 22 '22 at 15:33
  • Caroline, the issue isn't with the pyplot because the scroll bar works when i just do plt.show() and i just display the graph on my screen. The issue is when put the graph in my streamlit... – Conor Segreti Dec 23 '22 at 16:11

0 Answers0