9 replies
June 2022

zouki-dev

My work around to get a nice chart:

import streamlit.components.v1 as components
import matplotlib.pyplot as plt
import mpld3
import streamlit as st
import matplotlib.pylab as pylab

#create your figure and get the figure object returned

def st_pyplot(fig):
size = fig.get_size_inches()
width = int(size[0]) * 100+50
height = int(size[1]) * 100+50
params = {‘legend.fontsize’: 30,
‘figure.figsize’: (10, 10),
‘axes.labelsize’: 30,
‘axes.titlesize’: 30,
‘xtick.labelsize’: 30,
‘ytick.labelsize’: 30}
pylab.rcParams.update(params)
fig_html = mpld3.fig_to_html(fig)
components.html(fig_html, width=width, height=height)

if name == “main”:
fig = plt.figure()
# fig = plt.figure(figsize=(15,10))
plt.plot([1, 2, 3, 5, 8, 13, 21, 34, 55, 89])
plt.xlabel(“Length (nm)”)
plt.ylabel(“Force (pN)”)
st_pyplot(fig)

1 reply
September 2022

Rudra_Bandhu

Hi,
thanks for the pointer to zoom in a plot interactively.
I am trying to do the same with an image file.

One question I have is, after I zoom in, can I get the coordinates of the region that is in display after zooming in?

Thanks,
Rudra

June 2023 ▶ zouki-dev

ibaha

I like this and it is helping me for 2D plots. Is there a way to make this work for 3D plots for example for this plot below?
x = [0, 1, 2, 3, 4, 5]
y = [0, 1, 2, 3, 4, 5]
z = [0, 1, 2, 3, 4, 5]
fig = plt.figure()
ax = plt.axes(projection=“3d”)
ax.scatter(x, y, z, c=‘g’, s=20)
ax.plot(x, y, z)
ax.set_xlabel(‘X Label’), ax.set_ylabel(‘Y Label’), ax.set_zlabel(‘Z Label’)
plt.show()

1 reply
June 2023 ▶ ibaha

willhuang Streamlit Team Member

Hi @ibaha , there is a known limitation where 3d plots do not work at this current moment :frowning:

1 reply
June 2023 ▶ willhuang

ibaha

@willhuang, are you serious? OMG, that’s going to kill what I am trying to do. I wanted to have rotatable and zoomable simple 3D plot with some simple boxes in it. Is it not doable in streamlit now? STREAMLIT DEVELOPERS, if you hear me, is that not possible?

2 replies
June 2023

willhuang Streamlit Team Member

Here is a possible solution that you could do?

June 2023 ▶ ibaha

edsaac Streamlit Community Moderator

For 3D visualizations I’d recommend using pyvista (and stpyvista for rendering that in streamlit), or even plotly for simpler plots. Matplotlib is great for anything in 2D, but it is not really designed for 3D or interactivity.

1 reply
June 2023 ▶ edsaac

ibaha

@edsaac, thanks for your recommendation. pyvista doesn’t seem to have zoom/rotate readily available. stpyvista on the other hand has that, which is what I needed.

November 2023

lurifaxel

Love this! Is there some way to click the plot and get the data from those points?