How to plot more than one line charts in a single line chart. And also add different color to different lines. Add legend to understand which color represents which lines. I tried two different codes, but none of the works.
Code 1:
st.line_chart(stock, x="ds", y="y", color="#0514C0")
st.line_chart(prediction, x="ds", y="y", color="#4CC005")
Code 2:
fig = px.line(stock, x="ds", y="y")
fig = px.line(prediction, x="ds", y="y")
# Plot!
st.plotly_chart(fig, use_container_width=True)
Hi @Charly_Wargnier
I need to plot similar to this:
But this should be interactive, like your graph
I’ve answered here:
If you want to have it in Plotly, try this code:
import streamlit as st
import plotly.graph_objs as go
import pandas as pd
import numpy as np
dates = pd.date_range(start='2012-01-01', end='2024-01-01', freq='M')
actual_prices = np.abs(np.random.normal(loc=0.0, scale=10, size=len(dates))).cumsum() + 50
split_index = len(dates) // 2
trace1 = go.Scatter(x=dates[:split_index], y=actual_prices[:split_index], mode='lines', name='Price (First Half)', line=dict(color='blue'))
trace2 = go.Scatter(x=da…
Let’s try to keep the discussion there
Best,
Charly
system
Closed
October 2, 2024, 1:47pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.