How to plot a graph in streamlit?

I’m trying to plot a graph in my streamlit app, but it just gives me an error. I’ve tried some ways to plot and I can’t fix the problem. Can anyone tell me what I should change in the code?

fig1 = plt.figure()
plt.axhline(0, linewidth=0.3, color='black')
plt.plot(1.477*r, v(u, l))
plt.plot([1.477/umin,1.477/umax],[vmin,vmax],'bo')
plt.xlabel("r [km]")
plt.title("Energia potencial efetiva")
plt.axis([0, 1.477*rmax, -0.5, vlim + 0.1])
st.pyplot(fig1)

enter image description here

Hi @isa.rsn,

What you’ve done looks correct on the surface. It would help if you could share the exact error message and the traceback so we can identify the error. Additionally, what are the values of your variables?

When I set all the variables (r, umin, umax, etc) to 1, I do get a valid plot (see attached code and screenshot). So I suspect your syntax is correct, and the error stems from one or more of the variables.

import streamlit as st
import matplotlib.pyplot as plt

fig1 = plt.figure()
plt.axhline(0, linewidth=0.3, color='black')
plt.plot(1.477*1, 1)
plt.plot([1.477/1,1.477/1],[1,1],'bo')
plt.xlabel("r [km]")
plt.title("Energia potencial efetiva")
plt.axis([0, 1.477*1, -0.5, 1 + 0.1])
st.pyplot(fig1)

Best,
Snehan

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.