lightweight-charts-python
lightweight-charts-python copied to clipboard
Add price axis to histogram subchart?
Question
Hello! I am trying to work with lightweight charts in python (key word trying), but ran into a problem. I created a histogram subchart to display close data in histogram form under the main chart. However, the price axis disappeared on that pane. How do I get it to show?
Also, is there a way to enable the vertical crosshair on the histogram while hovering on the main chart?
Thanks guys
Code example
import pandas as pd
from lightweight_charts.widgets import StreamlitChart
import streamlit as st
st.set_page_config(layout='wide')
chart = StreamlitChart(inner_width=1, inner_height=.6, height=750)
chart.candle_style(up_color='#089981', down_color='#f23645',
border_up_color='#089981', border_down_color='#f23645',
wick_up_color='#089981', wick_down_color='#f23645')
chart.volume_config(up_color='rgba(38, 166, 154,0.5)', down_color='rgba(239, 83, 80,0.5)')
chart.layout(background_color='rgba(20,23,33)')
chart.grid(color='rgba(68, 68, 68, 0.3)')
chart.legend(visible=True, font_size=11)
chart.time_scale(visible=False)
def calculate_sma(df,period: int=50):
return pd.DataFrame({
'time': df['date'],
f'SMA {period}' : df['close'].rolling(window=period).mean()
})
df = pd.read_csv('ohlcv.csv')
chart.set(df)
sma_data = calculate_sma(df,period=50)
sma_line = chart.create_line('SMA 50', price_line=False,price_label=False)
sma_line.set(sma_data)
chart2 = chart.create_subchart(position='bottom',width=1,height=.4,sync=True)
chart2.layout(background_color='rgba(20,23,33)')
chart2.legend(visible=True, font_size=11)
chart2.grid(color='rgba(68, 68, 68, 0.3)')
close_hist = chart2.create_histogram('close', price_line=False,price_label=False)
close_hist.set(df[['date','close']])
chart.load()
how to set topbar background_color