首页 > 解决方案 > Plotly:在股价图表中绘制条形图

问题描述

我有一张苹果股票价格的图表。我想在图表底部添加一个条形图来显示一些计算。(类似于音量条形图)。我可以分别绘制两个图表,但不能一起绘制..

如果我运行我的代码,错误是

plotly.exceptions.PlotlyRequestError: Hi there! Accounts on the Community Plan cannot create folders.
To save this file on Plotly, please remove the folder in your filename path. 

就像我需要一个高级帐户一样。那有必要吗?

这是我的代码。在第一部分中,我绘制股票图表,在第二部分中,我绘制条形图(“情绪图表”)。

import plotly.plotly as py
from plotly.tools import FigureFactory as FF
from datetime import datetime


df = web.DataReader("aapl", 'yahoo', datetime(2010, 10, 1), datetime(2019, 1, 15))
fig = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index)
py.plot(fig, filename='finance/aapl-candlestick', validate=False)

df = pd.read_csv('results_data_bar.csv', encoding="ISO-8859-1")

import plotly.plotly as py
import plotly.graph_objs as go

data = [
    go.Bar(
        x=df['Date'],
        y=df['count_sentiment_svm'],
        width= 0.8,
        marker=dict(
            color='rgb(0,100,0)',
            line=dict(
                color='rgb(100,100,100)',
                width=1.5,
            )
        )

    ),
    go.Bar(
        x=df['Date'],
        y=df['count_sentiment_svm_neg'],
        width= 0.8,
        marker=dict(
            color='rgb(100,0,0)',
            line=dict(
                color='rgb(100,100,100)',
                width=1.5,
            )
        )

    ),
]
layout = go.Layout(
    barmode='stack',
    title='Sentiment'
)

fig = go.Figure(data=data, layout=layout)

# IPython notebook
# py.iplot(fig, filename='pandas-bar-chart-layout')

py.plot(data, filename='stacked-bar')

标签: pythonpandaschartsplotly

解决方案


也许您需要尝试在离线模式下使用 plotly?如:

# import plotly in offline mode
import plotly.offline as py
# That's line needed if you use jupyter notebook (.ipynb):
init_notebook_mode(connected=True)
# your data, traces, layout are here
# And plot after that (for jupyter notebook):
py.iplot(fig)
# Or just py.plot if using python scripts (.py):
py.plot(fig)

来自官方文档 -链接


推荐阅读