python - 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')
解决方案
也许您需要尝试在离线模式下使用 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)
来自官方文档 -链接
推荐阅读
- java - 当我尝试在新的 FXML 上重定向用户时出现问题
- nginx - Nginx - 通用将所有 www 重定向到非 www
- unit-testing - 如何在需要 UserManager 但使用内存数据库的 XUnit 中测试方法
- python - 如何创建一个 For 循环来创建多个 URL 地址(仅更改一个)?
- c# - StartCoroutine 给出 NullReferenceException
- c++14 - 为什么这段代码给出分段错误?
- botframework - 如何将 V4 机器人转换为技能?
- git - Git - 行特定哈希\标签
- tensorflow - TensorFlow 模型到 TFLITE
- java - 创建一个与一个对象相关联但具有不同特征的对象