0

I am creating a function that returns multiple graphs (a total of 9 nos). I need to see the graphs in plotlys dashboard. when I am running the code a blank graph is coming. Please see the attached image. I am expecting 9 different graphs on that webpage.

Please see my code below. May I know where I went wrong? My sample data set is available here[].

Please see my code below

    import plotly as py
    import plotly
    import cufflinks as cf
    import pandas as pd
    import numpy as np
    from plotly.offline import download_plotlyjs, init_notebook_mode,plot, iplot
    init_notebook_mode(connected=True)
    cf.go_offline()
    
    import dash
    import dash_core_components as dcc
    import dash_html_components as html
    from dash.dependencies import Input,Output
    import plotly.graph_objects as go
    app = dash.Dash(__name__)
    
    def _create_fig():
        
        df_Noise=pd.read_csv('Funct_Noise_Corners_2p0_A.txt',delim_whitespace=True)
        df_noise_50 = df_Noise[(df_Noise['Temp(deg)'] == -20)| (df_Noise['Temp(deg)'] == 25)| (df_Noise['Temp(deg)'] == 50)]
        df_50_08_16 = df_noise_50[(df_noise_50['Frequency[MHz]'] == 0.8)| (df_noise_50['Frequency[MHz]'] == 1.6)]
        df_50_08_16_PVT=pd.pivot_table(df_50_08_16, index = ['Device_ID', 'Temp(deg)' ,'Supply[V]'],columns='Frequency[MHz]',values = 'NoiseLevel[dB]')
        df_50_08_16_PVT['SPEC_MAX']=-96.5
        fig0=df_50_08_16_PVT.iplot(asFigure=True,title='NOISE@_0.8Mhz_1.6MhzTemp_Range_Upto_50Deg')
        
        df_50_04_24_48 = df_noise_50[(df_noise_50['Frequency[MHz]'] == 2.4)| (df_noise_50['Frequency[MHz]'] == 4.8)| (df_noise_50['Frequency[MHz]'] == 0.4)]
        df_50_04_24_48_PVT=pd.pivot_table(df_50_04_24_48 , index = ['Device_ID', 'Temp(deg)' ,'Supply[V]'],columns='Frequency[MHz]',values = 'NoiseLevel[dB]')
        df_50_04_24_48_PVT['SPEC_MAX']=-99.5
        fig1=df_50_04_24_48_PVT.iplot(asFigure=True,title='NOISE@_0.4Mhz_2.4Mhz_4.8Mhz_Temp_Range_Upto_50Deg')
        
        df_8_16 = df_Noise[(df_Noise['Frequency[MHz]'] == 0.8)| (df_Noise['Frequency[MHz]'] == 1.6)]
        df_8_16_PVT=pd.pivot_table(df_8_16 , index = ['Device_ID', 'Temp(deg)' ,'Supply[V]'],columns='Frequency[MHz]',values = 'NoiseLevel[dB]')
        df_8_16_PVT['SPEC_MAX']=-96.5
        fig2=df_8_16_PVT.iplot(asFigure=True,title='NOISE@_0.8Mhz_1.6Mhz_All_Temp_Range')
        
        df_04_24_48 = df_Noise[(df_Noise['Frequency[MHz]'] == 2.4)| (df_Noise['Frequency[MHz]'] == 4.8)| (df_Noise['Frequency[MHz]'] == 0.4)]
        df_04_24_48_PVT=pd.pivot_table(df_04_24_48 , index = ['Device_ID', 'Temp(deg)' ,'Supply[V]'],columns = 'Frequency[MHz]',values = 'NoiseLevel[dB]')
        df_04_24_48_PVT['SPEC_MAX']=-99.5
        fig3=df_04_24_48_PVT.iplot(asFigure=True,title='NOISE@_0.4Mhz_2.4Mhz_4.8Mhz_All_Temp_Range')
        
        df_TDEN=pd.read_csv('Funct_TDEN_Corners_2p0_A.txt',delim_whitespace=True)
        df_TDEN_PVT = pd.pivot_table(df_TDEN, index = ['Device_ID', 'Temp(deg)' ,'Supply[V]'],columns='Frequency[MHz]',values =['TDEN_Rise[ns]','TDEN_Fall[ns]'] )
        df_TDEN_PVT['SPEC_MAX']=80
        df_TDEN_PVT['SPEC_MIN']=50
        fig4=df_TDEN_PVT.iplot(asFigure=True,title='TDEN_CAP_LOAD_50pF')
        
        df_RT_FT_04=df_TDEN[(df_TDEN['Frequency[MHz]'] == 0.4)]
        df_RT_FT_04_PVT = pd.pivot_table(df_RT_FT_04,index = ['Device_ID', 'Temp(deg)' ,'Supply[V]','Frequency[MHz]'],values =['Risetime[ns]','Falltime[ns]'] )
        fig5=df_RT_FT_04_PVT.iplot(asFigure=True,title='RT_FT_0.4Mhz_LOAD_50pF')
        
        df_RT_FT_24=df_TDEN[(df_TDEN['Frequency[MHz]'] == 2.4)]
        df_RT_FT_24_PVT = pd.pivot_table(df_RT_FT_24,index = ['Device_ID', 'Temp(deg)' ,'Supply[V]','Frequency[MHz]'],values =['Risetime[ns]','Falltime[ns]'] )
        df_RT_FT_24_PVT['SPEC_MAX']=80
        df_RT_FT_24_PVT['SPEC_MIN']=40
        fig6=df_RT_FT_24_PVT.iplot(asFigure=True,title='RT_FT_2.4Mhz_LOAD_50pF')
        
        df_RT_FT_37=df_TDEN[(df_TDEN['Frequency[MHz]'] == 3.07)]
        df_RT_FT_37_PVT = pd.pivot_table(df_RT_FT_37,index = ['Device_ID', 'Temp(deg)' ,'Supply[V]','Frequency[MHz]'],values =['Risetime[ns]','Falltime[ns]'] )
        df_RT_FT_37_PVT['SPEC_MAX'] =35
        df_RT_FT_37_PVT['SPEC_MIN'] =23
        fig7=df_RT_FT_37_PVT.iplot(asFigure=True,title='RT_FT_3.07Mhz_LOAD_50pF')
        
        df_TDH_RT=pd.read_csv('Funct_TDH_RISE_Corners_2p0_A.txt',delim_whitespace=True)
        df_TDH_RT_PVT = pd.pivot_table(df_TDH_RT,index = ['Device_ID', 'Temp(deg)' ,'Supply[V]'],columns='Frequency[MHz]',values =['TDH_Rise[ns]'] )
        df_TDH_RT_PVT['SPEC_MIN']=5
        df_TDH_RT_PVT['SPEC_MAX']=30 
        fig8 = df_TDH_RT_PVT.iplot(asFigure=True,title='TDH_RISE',width=3)   
     
    
        
        fig=[fig0,fig1,fig2,fig3,fig4,fig5,fig6,fig7,fig8]    
           
        return fig
    
    app.layout = html.Div([
        dcc.Graph(
            id='g1',
            figure=_create_fig()),
        dcc.Interval(
            id='interval-component',
            interval=1*1000, # in milliseconds
            n_intervals=0
        )
    ])
    
    
    @app.callback(
        dash.dependencies.Output('g1', 'figure'),
        dash.dependencies.Input('interval-component', 'n_intervals'))
    def refresh_data(n_clicks):
        return _create_fig()
    
    
    if __name__ == "__main__":
        app.run_server()

The graph obtained by using the above code

enter image description here

Hari
  • 333
  • 6
  • 18
  • 2
    Please include all necessary data samples ***in*** your question, and not links to raw data contained in another post. There are several ways you can do this. I find [this approach](https://stackoverflow.com/questions/63163251/pandas-how-to-easily-share-a-sample-dataframe-using-df-to-dict/63163254#63163254) to be the most useful. – vestland Jul 06 '21 at 12:10
  • May i know any issue in my function.When the function gets called no graph is coming. – Hari Jul 06 '21 at 12:22

1 Answers1

1

First off, you'll be able to find more hints for any errors in your Dash code if you run the server in your main using app.run_server(debug=True) while developing.

In your case, you should see an error message like this:

Invalid argument `figure` passed into Graph with ID "g1".
Expected `object`.
Was supplied type `array`.

And indeed, you are passing a list of figures as figure to your dcc.Graph object with id=g1. Howver, this can only be a single figure, not a list of them.

Some suggestions for alternative approaches to fix this:

  1. Use plotly.subplots.make_subplots to create a single figure where each of your current 9 figures is a single subplots.
  2. Use multiple dcc.Graph objects in your layout, one per figure.
  3. If you don't need to access the graphs at any other point in the code, you could create 9 dcc.Graph objects in and pass them as a list to a container Div in your layout.

Whatever you choose to try, I suggest trying it with some dummy data first and only start incorporating "real" data once you figured out the basic layout.

Michel
  • 769
  • 4
  • 19