<tfoot id='9jL6q'></tfoot>

<legend id='9jL6q'><style id='9jL6q'><dir id='9jL6q'><q id='9jL6q'></q></dir></style></legend>
    1. <small id='9jL6q'></small><noframes id='9jL6q'>

    2. <i id='9jL6q'><tr id='9jL6q'><dt id='9jL6q'><q id='9jL6q'><span id='9jL6q'><b id='9jL6q'><form id='9jL6q'><ins id='9jL6q'></ins><ul id='9jL6q'></ul><sub id='9jL6q'></sub></form><legend id='9jL6q'></legend><bdo id='9jL6q'><pre id='9jL6q'><center id='9jL6q'></center></pre></bdo></b><th id='9jL6q'></th></span></q></dt></tr></i><div id='9jL6q'><tfoot id='9jL6q'></tfoot><dl id='9jL6q'><fieldset id='9jL6q'></fieldset></dl></div>
      • <bdo id='9jL6q'></bdo><ul id='9jL6q'></ul>

      1. Plotly:如何向烛台图添加交易量

        Plotly: How to add volume to a candlestick chart(Plotly:如何向烛台图添加交易量)
          <tbody id='weaOv'></tbody>

        <small id='weaOv'></small><noframes id='weaOv'>

            <bdo id='weaOv'></bdo><ul id='weaOv'></ul>
          • <i id='weaOv'><tr id='weaOv'><dt id='weaOv'><q id='weaOv'><span id='weaOv'><b id='weaOv'><form id='weaOv'><ins id='weaOv'></ins><ul id='weaOv'></ul><sub id='weaOv'></sub></form><legend id='weaOv'></legend><bdo id='weaOv'><pre id='weaOv'><center id='weaOv'></center></pre></bdo></b><th id='weaOv'></th></span></q></dt></tr></i><div id='weaOv'><tfoot id='weaOv'></tfoot><dl id='weaOv'><fieldset id='weaOv'></fieldset></dl></div>

            1. <legend id='weaOv'><style id='weaOv'><dir id='weaOv'><q id='weaOv'></q></dir></style></legend>
              <tfoot id='weaOv'></tfoot>

                • 本文介绍了Plotly:如何向烛台图添加交易量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  代码:

                  from plotly.offline import init_notebook_mode, iplot, iplot_mpldef plot_train_test(train, test, date_split):数据 = [Candlestick(x=train.index, open=train['open'], high=train['high'], low=train['low'], close=train['close'],name='火车'),Candlestick(x=test.index, open=test['open'], high=test['high'], low=test['low'], close=test['close'],name='test')]布局 = {形状":[{'x0':date_split,'x1':date_split,'y0':0,'y1':1,'xref':'x','yref':'paper','line': {'color': 'rgb(0,0,0)', 'width': 1}}],'annotations': [{'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'left','text': ' 测试数据'},{'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'right', 'text': '训练数据'}] }图=图(数据=数据,布局=布局)iplot(图)

                  上面的代码没问题.但是现在我想在这个烛台图表中成交量"

                  代码:

                  from plotly.offline import init_notebook_mode, iplot, iplot_mpldef plot_train_test(train, test, date_split):data = [Candlestick(x=train.index, open=train['open'], high=train['high'], low=train['low'], close=train['close'],volume=train['卷'],名称='火车'),Candlestick(x=test.index, open=test['open'], high=test['high'], low=test['low'],close=test['close'],volume=test['volume'],name='测试')]布局 = {形状":[{'x0':date_split,'x1':date_split,'y0':0,'y1':1,'xref':'x','yref':'paper','line': {'color': 'rgb(0,0,0)', 'width': 1}}],注释":[{'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'left','text': '测试数据'},{'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'right','文本':'训练数据'}]}图=图(数据=数据,布局=布局)iplot(图)

                  错误:

                  <块引用>

                  ValueError:为类型对象指定的属性无效plotly.graph_objs.Candlestick: '音量'

                  解决方案

                  您还没有提供完整的代码片段和数据示例,所以我将不得不提出一个基于示例的解决方案

                  完整代码:

                  导入 plotly.graph_objects从 plotly.subplots 导入 make_subplots将熊猫导入为 pd# 数据df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')# 创建带有辅助 y 轴的图形fig = make_subplots(specs=[[{"secondary_y": True}]])# 包含带有范围选择器的烛台fig.add_trace(go.Candlestick(x=df['Date'],开=df['AAPL.Open'],高=df['AAPL.High'],低=df['AAPL.Low'], 关闭=df['AAPL.Close']),次要_y =真)# 包括卷的 go.Bar 跟踪fig.add_trace(go.Bar(x=df['Date'], y=df['AAPL.Volume']),次要_y=假)fig.layout.yaxis2.showgrid=False图.show()

                  code:

                  from plotly.offline import init_notebook_mode, iplot, iplot_mpl
                      
                  def plot_train_test(train, test, date_split):
                      data = [Candlestick(x=train.index, open=train['open'], high=train['high'], low=train['low'], close=train['close'],name='train'),
                             Candlestick(x=test.index, open=test['open'], high=test['high'], low=test['low'], close=test['close'],name='test')
                              ]
                              layout = {
                                  'shapes': [
                                      {'x0': date_split, 'x1': date_split, 'y0': 0, 'y1': 1, 'xref': 'x', 'yref': 'paper',
                                       'line': {'color': 'rgb(0,0,0)', 'width': 1}}],
                                  'annotations': [{'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'left','text': ' test data'},
                                      {'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'right', 'text': 'train data '}] }
                              figure = Figure(data=data, layout=layout)
                              iplot(figure)
                  

                  The above code is ok.But now I want to 'volume' in this candlestick chart

                  code:

                  from plotly.offline import init_notebook_mode, iplot, iplot_mpl
                          
                  def plot_train_test(train, test, date_split):
                      data = [Candlestick(x=train.index, open=train['open'], high=train['high'], low=train['low'], close=train['close'],volume=train['volume'],name='train'),
                             Candlestick(x=test.index, open=test['open'], high=test['high'], low=test['low'],close=test['close'],volume=test['volume'],name='test')]
                              layout = {
                                  'shapes': [
                                      {'x0': date_split, 'x1': date_split, 'y0': 0, 'y1': 1, 'xref': 'x', 'yref': 'paper',
                                       'line': {'color': 'rgb(0,0,0)', 'width': 1}}
                                  ],
                                  'annotations': [
                                      {'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'left',
                                       'text': ' test data'},
                                      {'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'right',
                                       'text': 'train data '}
                                  ]
                              }
                              figure = Figure(data=data, layout=layout)
                              iplot(figure) 
                  

                  error:

                  ValueError: Invalid property specified for object of type plotly.graph_objs.Candlestick: 'volume'

                  解决方案

                  You haven't provided a complete code snippet with a data sample, so I'm going to have to suggest a solution that builds on an example here.

                  In any case, you're getting that error message simply because go.Candlestick does not have a Volume attribute. And it might not seem so at first, but you can easily set up go.Candlestick as an individual trace, and then include an individual go.Bar() trace for Volumes using:

                  1. fig = make_subplots(specs=[[{"secondary_y": True}]])
                  2. fig.add_traces(go.Candlestick(...), secondary_y=True)
                  3. fig.add_traces(go.Bar(...), secondary_y=False)

                  Plot:

                  Complete code:

                  import plotly.graph_objects as go
                  from plotly.subplots import make_subplots
                  import pandas as pd
                  
                  # data
                  df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
                  
                  # Create figure with secondary y-axis
                  fig = make_subplots(specs=[[{"secondary_y": True}]])
                  
                  # include candlestick with rangeselector
                  fig.add_trace(go.Candlestick(x=df['Date'],
                                  open=df['AAPL.Open'], high=df['AAPL.High'],
                                  low=df['AAPL.Low'], close=df['AAPL.Close']),
                                 secondary_y=True)
                  
                  # include a go.Bar trace for volumes
                  fig.add_trace(go.Bar(x=df['Date'], y=df['AAPL.Volume']),
                                 secondary_y=False)
                  
                  fig.layout.yaxis2.showgrid=False
                  fig.show()
                  

                  这篇关于Plotly:如何向烛台图添加交易量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                    <i id='Lehcd'><tr id='Lehcd'><dt id='Lehcd'><q id='Lehcd'><span id='Lehcd'><b id='Lehcd'><form id='Lehcd'><ins id='Lehcd'></ins><ul id='Lehcd'></ul><sub id='Lehcd'></sub></form><legend id='Lehcd'></legend><bdo id='Lehcd'><pre id='Lehcd'><center id='Lehcd'></center></pre></bdo></b><th id='Lehcd'></th></span></q></dt></tr></i><div id='Lehcd'><tfoot id='Lehcd'></tfoot><dl id='Lehcd'><fieldset id='Lehcd'></fieldset></dl></div>

                            <bdo id='Lehcd'></bdo><ul id='Lehcd'></ul>

                              <tbody id='Lehcd'></tbody>

                            <legend id='Lehcd'><style id='Lehcd'><dir id='Lehcd'><q id='Lehcd'></q></dir></style></legend>
                            <tfoot id='Lehcd'></tfoot>
                          • <small id='Lehcd'></small><noframes id='Lehcd'>