How to add xaxis parameter to create_candlestick in plotly?


#1

i am trying to setup the xaxis so that my candlestick chart displays all the intermediate values. I cannot figure out how to set the xaxis parameter so that plotly does not give me an error:

fig =  FF.create_candlestick(df['OPEN'], df['HIGH'], df['LOW'], df['CLOSE'], dates=df['DATE'], xaxis=dict(
        autorange=False,
        showgrid=False,
        zeroline=False,
        showline=False,
        autotick=True,
        ticks='',
        showticklabels=False
    )
)

#fig['data'].extend([trace])

py.image.save_as(fig, filename='out.png', width=10000, height=1200)

The error message that i get from plotly is following:

Traceback (most recent call last):
  File "./plot.py", line 63, in <module>
    py.image.save_as(fig, filename='out.png', width=10000, height=1200)
  File "/home/merr/.local/lib/python2.7/site-packages/plotly/plotly/plotly.py", line 787, in save_as
    img = cls.get(figure_or_data, format, width, height, scale)
  File "/home/merr/.local/lib/python2.7/site-packages/plotly/plotly/plotly.py", line 710, in get
    raise exceptions.PlotlyError(return_data['error'])
KeyError: 'error'

If i remove the xaxis part then it works well but skips some xaxis values on my chart, please see the image below, it only shows months, not days on the xaxis.
enter image description here

Also, i would like to display vertical lines for each xaxis value, is that achievable?

Thanks!


#2

Not to derail your question but I see you are “extend” in your fig. Could you explain this? Is this extending your ohlc graph without reloading the entire graph? I have not found a viable solution to extend instead of reload the ohcld graph.

#fig[‘data’].extend([trace])


#3

I have the answer for my own question as reference.

from plotly.graph_objs import *
 ##########################  CREATE OHLCV FORMAT  ###############################
    trace = Candlestick(
        x=NewDateTimes,
        open=AppendedValue['open'],
        high=AppendedValue['high'],
        low=AppendedValue['low'],
        close=AppendedValue['close'],
        showlegend=False,
        name='XRP/USD',
        legendgroup='XRP/USD',
        increasing=dict(line=dict(color=colorscale[2])),
        decreasing=dict(line=dict(color=colorscale[4])),
        yaxis='y1'
    )
    data=[trace]
    ######################  END CREATE OHLCV FORMAT  ###############################