Hello about 2nd axis

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 :wink:

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 = fig.add_subplot(111)
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 :slight_smile: hope to hear from your Streamlit adventures soon !