Python 虚线图不显示

Python 虚线图不显示,python,graph,plotly-dash,hyphen,Python,Graph,Plotly Dash,Hyphen,我想用破折号画一张图表。当我在Plotly中复制这些示例时,效果很好,但是当我用我的值更改一些变量并运行它时,除了图形之外,所有元素都会出现 代码如下: app = dash.Dash(__name__) app.layout = html.Div([ dcc.Graph(id='graph-with-slider'), dcc.Slider( id='year-slider', min=subset_date['Year'].unique().

我想用破折号画一张图表。当我在Plotly中复制这些示例时,效果很好,但是当我用我的值更改一些变量并运行它时,除了图形之外,所有元素都会出现

代码如下:

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Graph(id='graph-with-slider'),
    dcc.Slider(
        id='year-slider',
        min=subset_date['Year'].unique().min(),
        max=subset_date['Year'].unique().max(),
        value=subset_date['Year'].unique().min(),
        step=None

    )

])

@app.callback(
    Output('graph-with-slider', 'figure'),
    [Input('year-slider', 'value')])
def update_figure(selected_year):
    return {
        'data': go.Scatter(x=subset_date.index,
                          y=subset_date['Value'],
                          mode='lines'),
        'layout': go.Layout(
            title='My Title'
        )

    }

if __name__=='__main__':
    app.run_server()

我做错了什么?

下面是一个简单的应用程序布局:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

import pandas as pd
import plotly.graph_objs as go

# Step 1. Launch the application
app = dash.Dash()

# Step 2. Import the dataset

# Scimago Journal & Country Rank
# from www.scimagojr.com 
st = {'Date': ['2008-01-01', '2009-01-01', '2010-01-01', '2011-01-01', '2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01', '2016-01-01','2017-01-01', '2018-01-01'],
       # 'Turkey': [26526, 30839, 33325, 34926, 36766, 40302, 41400, 44529, 47138, 44584,45582],
        'Iran': [20006, 24509, 30013, 39682, 41513, 42252, 44923, 45013, 52538, 56029, 60268]
        }
st = pd.DataFrame(st)
# range slider options
st['Date'] = pd.to_datetime(st.Date)
dates = ['2008-01-01', '2009-01-01', '2010-01-01', '2011-01-01', '2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01', '2016-01-01','2017-01-01', '2018-01-01']
        



# Step 3. Create a plotly figure
trace_1 = go.Scatter(x = st.Date, y = st['Iran'],
                    name = 'Iran',
                    line = dict(width = 2,
                                color = 'rgb(229, 151, 50)'))
layout = go.Layout(title = 'Scimago Journal & Country Rank (Iran)',
                   hovermode = 'closest')
fig = go.Figure(data = [trace_1], layout = layout)


# Step 4. Create a Dash layout
app.layout = html.Div([
               
                # adding a plot
                dcc.Graph(id = 'plot', figure = fig),

                
                
                # range slider
               
                   
                    dcc.RangeSlider(id = 'slider',
                                    marks = {i : dates[i] for i in range(0, 11)},
                                    min = 0,
                                    max = 10,
                                    value = [1, 7])
])
                       
                   


# Step 5. Add callback functions
@app.callback(Output('plot', 'figure'),
             [
             Input('slider', 'value')])
def update_figure( input2):
    # filtering the data
    st2 = st[(st.Date > dates[input2[0]]) & (st.Date < dates[input2[1]])]
    # updating the plot
    trace_1 = go.Scatter(x = st2.Date, y = st2['Iran'],
                        name = 'Iran',
                      #  mode = 'markers'
                       line = dict(width = 2,
                                color = 'rgb(229, 151, 50)'))
                        
    
    fig = go.Figure(data = [trace_1], layout = layout)
    return fig
  
# Step 6. Add the server clause
if __name__ == '__main__':
    app.run_server(debug = False)
导入破折号
将仪表板核心组件作为dcc导入
将dash_html_组件导入为html
从dash.dependencies导入输入,输出
作为pd进口熊猫
导入plotly.graph_objs作为go
#第一步。启动应用程序
app=dash.dash()
#第二步。导入数据集
#Scimago杂志和国家排名
#来自www.scimagojr.com
st={‘日期’:[‘2008-01-01’、‘2009-01-01’、‘2010-01-01’、‘2011-01-01’、‘2012-01-01’、‘2013-01-01’、‘2014-01-01’、‘2015-01-01’、‘2016-01-01’、‘2017-01-01’、‘2018-01-01’],
#“土耳其”:[2652630839333325349263676640302414004452947138,445845582],
‘伊朗’:[20006245093001339682141513242252449234513525385602960268]
}
st=pd.数据帧(st)
#范围滑块选项
st['Date']=pd.to_datetime(st.Date)
日期=['2008-01-01','2009-01-01','2010-01-01','2011-01-01','2012-01-01','2013-01-01','2014-01-01','2015-01-01','2016-01-01','2017-01-01','2018-01-01']
#第三步。创建绘图图形
trace_1=go.Scatter(x=st.Date,y=st['Iran'],
名称='伊朗',
线条=笔迹(宽度=2,
颜色='rgb(229151,50'))
版面=go.版面(标题=‘Scimago杂志和国家排名(伊朗)’,
hovermode=‘最近’)
图=开始图(数据=[trace_1],布局=布局)
#第四步。创建短划线布局
app.layout=html.Div([
#添加绘图
dcc.图形(id=‘绘图’,图=图),
#范围滑块
dcc.RangeSlaider(id='slider',
marks={i:dates[i]表示范围(0,11)},
最小值=0,
最大值=10,
值=[1,7])
])
#第五步。添加回调函数
@应用程序回调(输出('plot','figure'),
[
输入('滑块','值')])
def更新图(输入2):
#过滤数据
st2=st[(st.Date>dates[input2[0]])和(st.Date
以下是一个简单的应用程序布局:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

import pandas as pd
import plotly.graph_objs as go

# Step 1. Launch the application
app = dash.Dash()

# Step 2. Import the dataset

# Scimago Journal & Country Rank
# from www.scimagojr.com 
st = {'Date': ['2008-01-01', '2009-01-01', '2010-01-01', '2011-01-01', '2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01', '2016-01-01','2017-01-01', '2018-01-01'],
       # 'Turkey': [26526, 30839, 33325, 34926, 36766, 40302, 41400, 44529, 47138, 44584,45582],
        'Iran': [20006, 24509, 30013, 39682, 41513, 42252, 44923, 45013, 52538, 56029, 60268]
        }
st = pd.DataFrame(st)
# range slider options
st['Date'] = pd.to_datetime(st.Date)
dates = ['2008-01-01', '2009-01-01', '2010-01-01', '2011-01-01', '2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01', '2016-01-01','2017-01-01', '2018-01-01']
        



# Step 3. Create a plotly figure
trace_1 = go.Scatter(x = st.Date, y = st['Iran'],
                    name = 'Iran',
                    line = dict(width = 2,
                                color = 'rgb(229, 151, 50)'))
layout = go.Layout(title = 'Scimago Journal & Country Rank (Iran)',
                   hovermode = 'closest')
fig = go.Figure(data = [trace_1], layout = layout)


# Step 4. Create a Dash layout
app.layout = html.Div([
               
                # adding a plot
                dcc.Graph(id = 'plot', figure = fig),

                
                
                # range slider
               
                   
                    dcc.RangeSlider(id = 'slider',
                                    marks = {i : dates[i] for i in range(0, 11)},
                                    min = 0,
                                    max = 10,
                                    value = [1, 7])
])
                       
                   


# Step 5. Add callback functions
@app.callback(Output('plot', 'figure'),
             [
             Input('slider', 'value')])
def update_figure( input2):
    # filtering the data
    st2 = st[(st.Date > dates[input2[0]]) & (st.Date < dates[input2[1]])]
    # updating the plot
    trace_1 = go.Scatter(x = st2.Date, y = st2['Iran'],
                        name = 'Iran',
                      #  mode = 'markers'
                       line = dict(width = 2,
                                color = 'rgb(229, 151, 50)'))
                        
    
    fig = go.Figure(data = [trace_1], layout = layout)
    return fig
  
# Step 6. Add the server clause
if __name__ == '__main__':
    app.run_server(debug = False)
导入破折号
将仪表板核心组件作为dcc导入
将dash_html_组件导入为html
从dash.dependencies导入输入,输出
作为pd进口熊猫
导入plotly.graph_objs作为go
#第一步。启动应用程序
app=dash.dash()
#第二步。导入数据集
#Scimago杂志和国家排名
#来自www.scimagojr.com
st={‘日期’:[‘2008-01-01’、‘2009-01-01’、‘2010-01-01’、‘2011-01-01’、‘2012-01-01’、‘2013-01-01’、‘2014-01-01’、‘2015-01-01’、‘2016-01-01’、‘2017-01-01’、‘2018-01-01’],
#“土耳其”:[2652630839333325349263676640302414004452947138,445845582],
‘伊朗’:[20006245093001339682141513242252449234513525385602960268]
}
st=pd.数据帧(st)
#范围滑块选项
st['Date']=pd.to_datetime(st.Date)
日期=['2008-01-01','2009-01-01','2010-01-01','2011-01-01','2012-01-01','2013-01-01','2014-01-01','2015-01-01','2016-01-01','2017-01-01','2018-01-01']
#第三步。创建绘图图形
trace_1=go.Scatter(x=st.Date,y=st['Iran'],
名称='伊朗',
线条=笔迹(宽度=2,
颜色='rgb(229151,50'))
版面=go.版面(标题=‘Scimago杂志和国家排名(伊朗)’,
hovermode=‘最近’)
图=开始图(数据=[trace_1],布局=布局)
#第四步。创建短划线布局
app.layout=html.Div([
#添加绘图
dcc.图形(id=‘绘图’,图=图),
#范围滑块
dcc.RangeSlaider(id='slider',
marks={i:dates[i]表示范围(0,11)},
最小值=0,
最大值=10,
值=[1,7])
])
#第五步。添加回调函数
@应用程序回调(输出('plot','figure'),
[
输入('滑块','值')])
def更新图(输入2):
#过滤数据
st2=st[(st.Date>dates[input2[0]])和(st.Date
你能发布你的数据样本吗
subset\u date.head()
subset\u date.info()
你能发布你的数据样本吗<代码>子集_date.head()和
子集_date.info()