How to Plot stacked Go.Candlestick using python plotly like G0.Scatter

Friends, any quick solution to this will be of much helpful.

I have three sets of data as OHLC (Open High Low Close ) data .Here the X axis is shared across all the three differrent datasets.

Y axis split to plot the candle stick in the given area of these three data sets seperately but in one layout.

Tried this code

import pandas as pd
import numpy as np
from datetime import date

#import plotly
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
init_notebook_mode(connected=True)
#import plotly.plotly as py

SCRIPTCODE ="TEST"


df['open'] = [33.0, 33.3, 33.5, 33.0, 34.1]
df['high'] = [33.1, 33.3, 33.6, 33.2, 34.8]
df['low'] = [32.7, 32.7, 32.8, 32.6, 32.8]
df['close'] = [33.0, 32.9, 33.3, 33.1, 33.1]
df['dates'] = [datetime(year=2013, month=10, day=10),
         datetime(year=2013, month=11, day=10),
         datetime(year=2013, month=12, day=10),
         datetime(year=2014, month=1, day=10),
         datetime(year=2014, month=2, day=10)]


tracecan = go.Candlestick(x=df.index,
                       open=df['Open'],
                       high=df['High'],
                       low=df['Low'],
                       close=df['Close'])


candle_opt_ce_data = go.Candlestick(x=stock_opt_ce.index,
                       open=stock_opt_ce['Open'],
                       high=stock_opt_ce['High'],
                       low=stock_opt_ce['Low'],
                       close=stock_opt_ce['Close'])

candle_opt_pe_data = go.Candlestick(x=stock_opt_pe.index,
                       open=stock_opt_pe['Open'],
                       high=stock_opt_pe['High'],
                       low=stock_opt_pe['Low'],
                       close=stock_opt_pe['Close'])


layout = go.Layout(
    title = "CandleStick:{} CE_StrikePrice:{} PE_StikePrice:{} EXPIRY :{}-{}-{}".format(SCRIPTCODE,strike_pricece,strike_pricepe,EXPDATE,EXPMONTHH,EXPYEAR),
    xaxis = dict(
        range = ['STARTYEAR-STARTMONTH-STARTDATE','ENDYEAR-ENDMONTH-ENDDATE']
    ),
    yaxis=dict(
        domain=[0, 0.33]
    ),
    legend=dict(
        traceorder='reversed'
    ),
    yaxis2=dict(
        domain=[0.33, 0.66]
    ),
    yaxis3=dict(
        domain=[0.66, 1]
    )
)

data = [tracecan,candle_opt_ce_data,candle_opt_pe_data]
#py.iplot(data, filename='candlestick_datetime')
fig = go.Figure(data=data,layout=layout)
iplot(fig, filename = './CandleStickData-{}.html'.format(SCRIPTCODE))
plot(fig,show_link = True, filename = './CandleStickData-{}.html'.format(SCRIPTCODE))

Here what happens is all the data merged into one and plotted but i want the data to be plotted in each area allocated as per the layout defined above. How to achieve this? Also i dont want the bottom slider how to remove that one ?
1st image working one with line plot
2nd one is issue image,I want the candlestick in each devided layout as above and (no slider required here as shown in the issue image)

Refer the CandleStickData-ITC.png (Issue one)
Refer the “CorrelationOfEquityAndOptionData-ITC.png” for the kind of chart but in Candlestick i am looking for(Made using Scatter Line chart).
One more solution(As shown in the working snapshot data point of all to be displayed when i hover the mouse)

i want is when i mouse on the chart it should show all the three layout data values of each plot for quick reading of the data.

Any solution to this please .

Hi @mbmarx,

Could you please place your example code in a fenced code block (https://help.github.com/articles/creating-and-highlighting-code-blocks/)? Also, please make sure the example is reproducible by including the import statements and some sample data that shows the behavior that you are seeing.

Thanks!
-Jon

@jmmease i have added the dataframe look a like data and the imports however this can be used only as a reference.
you can define any three dataframe of open high low close with same date index. value can be of anything within the limit(Example provided above).

If the query is not clear ,once again i put it here .

Let say i have three differrent dataset A B C of OHLC(Open,High,Low,Close)
I want to plot candle stick for A B C in allocated layouts. Example three layout are defiend with the size 1 2 3.
In 1st layout are the A OHLC(Candlestick) data should come
In 2nd layout B OHLC data should come
In 3rd layout C OHLC data should come

Now what happens is all the data are plotted in one layout which i want to avoid.I am blocked on this and my work is completly affected.Any solution is highly appreciated.

@jmmease i have found a solution for the stacked candlestick plot in Y Y1 Y2 axis one by one.I will post the code after my testing today.This might be helpful for coding.

1 Like