 hello! I’m new to python, could anyone give me an example or link how I could draw a chart with two y-axis?Thanks!

Hey @macxl welcome to the forums ?

Hmmm do you have an example in mind , or a screenshot/Doodle of what you’re trying to achieve ? Are you talking about dual axis ?

There are examples in plotly, Matplotlib and Vegalite (and probably Altair too soemwhere) on this link and Streamlit natively exposes any plot from those librairies with st.plotly_graph, st.pyplot or st.vega_lite_chart. So if you can build the graph in those libs you can expose it on Streamlit, now it’s going to be a matter of taste for the plotting library to choose 1 Like

thank you for the key words! I will type the code here when I solve the problem

thank you for the key words! I will type the code here when I solve the problem

well, an simple example:

import matplotlib.pyplot as plt
import numpy as np
import streamlit as st

x = np.arange(0., np.e, 0.01)
y1 = np.exp(-x)
y2 = np.log(x)

fig = plt.figure()

ax1.plot(x, y1)
ax1.set_ylabel(‘Y values for exp(-x)’)
ax1.set_title(“Double Y axis”)

ax2 = ax1.twinx() # this is the important function
ax2.plot(x, y2, ‘r’)
ax2.set_xlim([0, np.e])
ax2.set_ylabel(‘Y values for ln(x)’)
ax2.set_xlabel(‘Same X for both exp(-x) and ln(x)’)

st.pyplot(plt)

Streamlit is really convenient!

1 Like

Glad you found out hope to hear from your Streamlit adventures soon !