Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scaleMargins is not working #14

Open
DemoreXTess opened this issue Jul 19, 2023 · 1 comment
Open

scaleMargins is not working #14

DemoreXTess opened this issue Jul 19, 2023 · 1 comment

Comments

@DemoreXTess
Copy link

DemoreXTess commented Jul 19, 2023

I made a basic candlestick chart with volume parameter but my volume histogram heights are huge. I tried to put them much lower places with bigger percentage values such as .9 from top but nothing changed. I need quick help please

@zlpatel
Copy link

zlpatel commented Jul 4, 2024

The issue could be related to this -> https://tradingview.github.io/lightweight-charts/docs/migrations/from-v3-to-v4#scalemargins-option-has-been-removed-from-series-options

You could use price_scale and overlay_price_scales option while defining Chart. See below example. This is working. But it is a chart level setting and could be an issue when you want to control scale margin for multiple overlay series chart.

sp500_2000_2001_chart = Chart(
    width = 1360,
    height = 500,
    time_scale=TimeScaleOptions(
        seconds_visible=True,
        time_visible=True),
    price_scale=PriceScaleOptions(scale_margins=PriceScaleMargins(top=0.1,bottom=0.4)),
    overlay_price_scales=OverlayPriceScaleOptions(scale_margins=PriceScaleMargins(top=0.7,bottom=0))
    )

sp500_2000_2001_chart.mark_candlestick(data=sp500_2000_2001)
#sp500_2000_2001_chart.mark_line(data=sp500_2000_2001.eval('value = close'), name = 'test', LineWidth=2)
sp500_2000_2001_chart.mark_histogram(series_name='Volume',data=sp500_2000_2001.eval('value = volume'),priceScaleId='',priceFormat={'type':'volume'})

Alternatively, I tried to fix this by making some code changes. you can download my code using this command -> pip install -U git+https://github.com/zlpatel/pytvlwcharts.git@patch-1

The only caveat is that you always need to pass price_scale parameter even though you don't want to set anything. I am still trying to figure out how to improve that so that we don't have to pass that parameter but meanwhile you can just set it to an empty object of PriceScaleMargins() like I did in the below example.

sp500_2000_2001_chart = Chart(
    width = 1360,
    height = 500,
    time_scale=TimeScaleOptions(
        seconds_visible=True,
        time_visible=True)
    #price_scale=PriceScaleOptions(scale_margins=PriceScaleMargins(top=0.1,bottom=0.4)),
    #overlay_price_scales=OverlayPriceScaleOptions(scale_margins=PriceScaleMargins(top=0.7,bottom=0))
    )

sp500_2000_2001_chart.mark_candlestick(series_name='ohlc',data=sp500_2000_2001, price_scale = PriceScaleOptions()) #scale_margins=PriceScaleMargins(top=0.1,bottom=0.4)))
sp500_2000_2001_chart.mark_line(data=sp500_2000_2001.eval('value = close'), price_scale = PriceScaleOptions(scale_margins=PriceScaleMargins(top=0.1,bottom=0.4)), name = 'test', LineWidth=0.5)
sp500_2000_2001_chart.mark_histogram(series_name='Volume',data=sp500_2000_2001.eval('value = volume'), price_scale = PriceScaleOptions(scale_margins=PriceScaleMargins(top=0.9,bottom=0)),priceScaleId='',priceFormat={'type':'volume'})

zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
zlpatel added a commit to zlpatel/pytvlwcharts that referenced this issue Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants