密谋:在股价图中绘制条形图

时间:2019-01-25 16:42:31

标签: python pandas charts 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')

1 个答案:

答案 0 :(得分:0)

也许您需要尝试在离线模式下使用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)

摘自官方文档-link