[BUG] sub chart sync issue
Expected Behavior
The vertical labels are shifted due to the large difference in values between the price chart and the subchart
import pandas as pd import ccxt from lightweight_charts import Chart import talib
def rsi(df, period: int = 14): return pd.DataFrame( {"time": df["time"], "RSI": talib.RSI(df["close"], timeperiod=period)} )
if name == 'main': # Initialize the ccxt exchange (for example, Binance) exchange = ccxt.binance() # Change this to another exchange if necessary
# Fetch OHLCV data (for example, for BTC/USDT on a 1-hour timeframe)
ohlcv = exchange.fetch_ohlcv('BTC/USDT', timeframe='1h', limit=1000)
# Convert the data to a pandas DataFrame
ohlcv_df = pd.DataFrame(ohlcv, columns=['time', 'open', 'high', 'low', 'close', 'volume'])
# Convert the time from timestamp to a readable datetime format
ohlcv_df['time'] = pd.to_datetime(ohlcv_df['time'], unit='ms')
# Initialize the chart
chart = Chart(inner_height=0.7)
chart.time_scale(visible=True) # Hide the time scale of the main chart
chart.layout(font_size=11)
# Create the RSI subchart
rsi_chart = chart.create_subchart(height=0.3, width=1, sync=True)
rsi_chart.layout(font_size=11)
rsi_df = rsi(ohlcv_df) # Get RSI data
rsi_line = rsi_chart.create_line("RSI") # Create line for RSI
rsi_line.set(rsi_df) # Set RSI data on the subchart
chart.legend(True, font_size=14) # Main chart
rsi_chart.legend(True) # Sub-chart
# Set the chart data (main chart)
chart.set(ohlcv_df)
# Show the chart
chart.show(block=True)
Environment
- OS:win 11
- Library:2.1
+1 I'd like to know how to go about resolving this issue.
chart = Chart(inner_width=1, inner_height=0.7, debug=True)
chart.time_scale(visible=False)
chart.price_scale(minimum_width=100)
chart2 = chart.create_subchart(width=1, height=0.3, sync=True)
chart2.price_scale(minimum_width=100)
line_rsi = chart2.create_line('rsi')
func price_scale(minimum_width=100) Setting minimum width on both sides solved my issue 💯
chart = Chart(inner_width=1, inner_height=0.7, debug=True) chart.time_scale(visible=False) chart.price_scale(minimum_width=100) chart2 = chart.create_subchart(width=1, height=0.3, sync=True) chart2.price_scale(minimum_width=100) line_rsi = chart2.create_line('rsi')func price_scale(minimum_width=100) Setting minimum width on both sides solved my issue 💯
Thanks a lot
Thanks!! This has been bothering me for a long time!