小编Nav*_*een的帖子

Python / Dash:图形的单个子图中的多个图形

我需要在 Dash 图中的图形的一个子图中有多个线图。

在下面的代码中,图中有 3 个子图 'Price' 、 'MMA30' 和 'Volume' 作为 3 个单独的子图。

我想在一个子图中包含“价格”和“MMA30”。

复制代码:

import dash,requests,pandas as pd
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly.tools as tls
from io import StringIO

app = dash.Dash(__name__)

app.layout = html.Div([
                html.Div(['Name : ', 
                          dcc.Input(id='input',value='ACC',type='text')
                          ]),       
             dcc.Graph(id='price_volume')
             ])


@app.callback(
        Output('price_volume', 'figure'),
        [Input(component_id='input', component_property = 'value')]
        )
def update_graph(in_data):

    p=requests.get('http://finance.google.com/finance/getprices?q='+in_data+'&x=NSE&i=61&p=1d&f=d,c,v').text
    a=pd.read_csv(StringIO(p),skiprows=range(7),names =['date','Close','Volume'])

    a['date']=pd.to_datetime(a.date.str[1:],unit='s').dt.tz_localize('UTC').dt.tz_convert('Asia/Kolkata')
    a['Date']=a.date.dt.date
    a['Time']=a.date.dt.time
    df = a[['Date','Time','Close','Volume']]

    df['MMA30']=df.Close.rolling(window=30).mean()

    fig = tls.make_subplots(rows=3, cols=1, shared_xaxes=True,vertical_spacing=0.009,horizontal_spacing=0.009)
    fig['layout']['margin'] …
Run Code Online (Sandbox Code Playgroud)

python plotly plotly-dash

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

plotly ×1

plotly-dash ×1

python ×1