简体   繁体   中英

Python Plotly prints two charts

Plotly seems to have this really annoying feature where it prints a minature version of the chart under the main chart. Can anybody explain how to get rid of the bottom chart? Im not sure why plotly even does this, seems pointless.

See my code and then the image attached.

ohlcv = go.Candlestick(x=df.index, open=df.Open, high=df.High, low=df.Low, close=df.Close, name='Currency Quote.html')
rolling_mean = go.Scatter(x=df.index, y=df.Rolling_Mean)
boll_upper = go.Scatter(x=df.index, y=df.Upper_Bollinger)
boll_lower = go.Scatter(x=df.index, y=df.Lower_Bollinger)
fig = tools.make_subplots(rows=1, cols=1, shared_xaxes=True)
fig.append_trace(ohlcv, 1, 1)  # row 1 col 1
fig.append_trace(rolling_mean, 1, 1)
fig.append_trace(boll_upper, 1, 1)
fig.append_trace(boll_lower, 1, 1)
py.offline.plot(fig, filename='CandleStick.html')

在此处输入图片说明

I am unable to replicate your exact graph since there is no sample data provided, but I took a sample candlestick graph and as you mentioned, came with a range slider by default.

I played around with the options and by using the property visible under the rangeslider property of xaxis under layout, we can disable the range slider completely!

Basically by setting the layout as shown below, we can remove the rangeslider!

layout = {
            "xaxis": {
                "rangeslider": {
                    "visible": False
                }
            }
         }

Please refer the below code and let me know if your issue is resolved!

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

open_data = [33.0, 33.3, 33.5, 33.0, 34.1]
high_data = [33.1, 33.3, 33.6, 33.2, 34.8]
low_data = [32.7, 32.7, 32.8, 32.6, 32.8]
close_data = [33.0, 32.9, 33.3, 33.1, 33.1]
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)]

trace = go.Candlestick(x=dates,
                       open=open_data,
                       high=high_data,
                       low=low_data,
                       close=close_data)
layout = {"xaxis": {
            "rangeslider": {
            "visible": False}
        }}
fig = go.Figure(data=[trace], layout=layout)
iplot(fig, filename='candlestick_datetime')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM