def Transfer(fileNumber, atomLocs1, atomLocs2, show=True, fitModules=[None], showCounts=False, showGenerationData=False,
             histBins=150, showFitDetails=False, savePlotlyFig=False, leanPlot=False, **standardTransferArgs):
    """
    Standard data analysis package for looking at survival rates throughout an experiment.
    """
    avgColor = '#FFFFFF'
    res = TransferAnalysis.standardTransferAnalysis(fileNumber, atomLocs1, atomLocs2, fitModules=fitModules,
                                   **standardTransferArgs)
    (atomLocs1, atomLocs2, transferData, transferErrs, initPopulation, pic1Data, keyName, key,
     repetitions, initThresholds, fits, avgTransferData, avgTransferErr, avgFit, avgPics, otherDimValues,
     locsList, genAvgs, genErrs, tt, transVarAvg, transVarErr, initAtomImages, transAtomImages,
     pic2Data, transThresholds, fitModules, transThresholdSame, basicInfoStr) = res
    if not show:
        return key, transferData, transferErrs, initPopulation
    
    # get the colors for the plots.
    pltColors, pltColors2 = getColors(len(locsList) + 1)
    scanType = "S." if atomLocs1 == atomLocs2 else "T."
    if scanType == "S.":
        legends = [r"%d,%d " % (loc1[0], loc1[1]) + (scanType + "% = " + str(errString(d[0], e[0])) if len(d) == 1
                   else "") for loc1, d, e in zip(locsList, transferData, transferErrs)]

    elif otherDimValues[0] is not None:
        legends = [r"%d,%d>%d,%d @%d " % (loc1[0], loc1[1], loc2[0], loc2[1], other) +
                   (scanType + "%=" + str(errString(d[0]), e[0]) if len(d) == 1 else "")
                   for loc1, loc2, d, e, other in zip(locsList, locsList, transferData, transferErrs,
                                                      otherDimValues)]
    else:
        legends = [r"%d,%d>%d,%d " % (loc1[0], loc1[1], loc2[0], loc2[1]) +
                   (scanType + "%=" + errString(d[0], e[0]) if len(d) == 1 else "")
                   for loc1, loc2, d, e in zip(locsList, locsList, transferData, transferErrs)]
    transferErrs = list(transferErrs)
    # Make the plots
    alphaVal = 0.5
    mainPlot, countsHist, countsFig, initPopPlot = [[] for _ in range(4)]
    avgFigs = [[] for _ in range(2)]
    avgFigs[0].append(go.Heatmap(z=avgPics[0], colorscale='Viridis'))
    avgFigs[1].append(go.Heatmap(z=avgPics[1], colorscale='Viridis'))
    fitCharacters = []
    
    if fitModules[0] is not None and showFitDetails:
        frames = getFitsDataFrame(fits, fitModules, avgFit)
        for frame in frames:
            display(frame)
    for data, err, loc, color, legend, fitData, gen, genErr, module in zip(transferData, transferErrs, locsList, pltColors,
                                                      legends, fits, genAvgs, genErrs, fitModules):
        mainPlot.append(go.Scatter(x=key, y=data, opacity=alphaVal, mode="markers", name=legend,
                                   error_y={"type": 'data', 'symmetric':False, "array": [e[1] for e in err], 
                                            'arrayminus':[e[0] for e in err],
                                            'color': color, 'visible':True},
                                   marker={'color': color}, legendgroup=legend))
        if showGenerationData:
            mainPlot.append(go.Scatter(x=key, y=gen, opacity=alphaVal, mode="markers", name=legend,
                                       error_y={"type": 'data', "array": genErr, 'color': color, 'visible':True},
                                       marker={'color': color, 'symbol': 'star'}, legendgroup=legend, showlegend=False))
        if fitModules[0] is not None:
            if fitData['vals'] is None:
                print(loc, 'Fit Failed!')
                continue
            if showFitDetails:
                fitCharacters.append(module.fitCharacter(fitData['vals']))
                mainPlot.append(go.Scatter(x=[0], y=[0.5], mode='text', text=[module.getFitCharacterString(fitData['vals'])], 
                                           textposition="top center", legendgroup=legend, showlegend=False))
                
            mainPlot.append(go.Scatter(x=fitData['x'], y=fitData['nom'], line={'color': color},
                                       legendgroup=legend, showlegend=False, opacity=alphaVal))
            if fitData['std'] is not None:
                rgbcolor = color.strip('#')
                rgbColor = tuple(int(rgbcolor[i:i+2], 16) for i in (0, 2, 4))
                mainPlot.append(go.Scatter(x=fitData['x'], y=fitData['nom'] + fitData['std'],
                                           opacity=alphaVal / 2, line={'color': color},
                                           legendgroup=legend, showlegend=False, hoverinfo='none'))
                mainPlot.append(go.Scatter(x=fitData['x'], y=fitData['nom'] - fitData['std'],
                                           opacity=alphaVal / 2, line={'color': color},
                                           legendgroup=legend, fill='tonexty', showlegend=False,
                                           hoverinfo='none', 
                                           fillcolor='rgba('+str(rgbColor[0])+', '+str(rgbColor[1])+', '+str(rgbColor[2])+', '+str(alphaVal/2) + ')'))
    transferPic = np.zeros(avgPics[0].shape)
    for i, loc in enumerate(atomLocs1):
        transferPic[loc[0], loc[1]] = np.mean(transferData[i])
    if fitModules[0] is not None and showFitDetails:
        print('Fit Character:', fitCharacters)
        print('Average Fit Character:', np.mean(fitCharacters), np.median(fitCharacters))
        fitCharacterPic, vmin, vmax = ah.genAvgDiscrepancyImage(fitCharacters, avgPics[0].shape, atomLocs1)
        fitCharacterFig = [go.Heatmap(z=fitCharacterPic, colorscale='Viridis', colorbar=go.heatmap.ColorBar(x=1, y=0.15, len=0.3))]
        layout = go.Layout(title='Fit-Character Pic')
        iplot(go.Figure(data=fitCharacterFig, layout=layout))
    maxHeight = np.max(arr([np.histogram(data.flatten(), bins=histBins)[0] for data in pic1Data]).flatten())
    for data, pop, loc1, loc2, color, threshold, legend in zip(pic1Data, initPopulation, atomLocs1, atomLocs2, pltColors,
                                                         initThresholds, legends):
        countsHist.append(go.Histogram(x=data, nbinsx=histBins, legendgroup=legend, showlegend=False, opacity=alphaVal/2,
                                       marker=dict(color=color)))
        countsHist.append(go.Scatter(y=[0, maxHeight], x=[threshold[0].t, threshold[0].t], showlegend=False,
                                     mode='lines', line={'color': color, 'width': 1}, hoverinfo='none',
                                     legendgroup=legend))
        initPopPlot.append(go.Scatter(x=key, y=pop, mode="markers", name=str(loc1),
                                      marker={'color': color}, legendgroup=legend, showlegend=False,
                                      opacity=alphaVal))
        
        avgFigs[0].append(go.Scatter(x=[loc1[1]], y=[loc1[0]], mode='markers', hoverinfo='none',
                                 showlegend=False, legendgroup=legend, marker={'size': 2, 'color': '#FF0000'}))
        avgFigs[1].append(go.Scatter(x=[loc2[1]], y=[loc2[0]], mode='markers', hoverinfo='none',
                                 showlegend=False, legendgroup=legend, marker={'size': 2, 'color': '#FF0000'}))
    # average stuff
    mainPlot.append(go.Scatter(x=key, y=avgTransferData, mode="markers", name='avg',
                               
                               error_y={"type": 'data', 'color': avgColor, 'symmetric':False, 
                                        "array": [e[1] for e in avgTransferErr], 'arrayminus':[e[0] for e in avgTransferErr]},
                               marker={'color': avgColor}, legendgroup='avg'))
    if fitModules[0] is not None:
        mainPlot.append(go.Scatter(x=avgFit['x'], y=avgFit['nom'], line={'color': avgColor},
                                   legendgroup='avg', showlegend=False, opacity=alphaVal))
        mainPlot.append(go.Scatter(x=[0], y=[0.5], mode='text', text=[fitModules[-1].getFitCharacterString(avgFit['vals'])], 
                                   textposition="top center", legendgroup='avg', showlegend=False))
        if avgFit['std'] is not None:
            mainPlot.append(go.Scatter(x=avgFit['x'], y=avgFit['nom'] + avgFit['std'],
                                       opacity=alphaVal / 2, line={'color': avgColor},
                                       legendgroup='avg', showlegend=False, hoverinfo='none'))
            mainPlot.append(go.Scatter(x=avgFit['x'], y=avgFit['nom'] - avgFit['std'],
                                       opacity=alphaVal / 2, line={'color': avgColor},
                                       legendgroup='avg', fill='tonexty', showlegend=False,
                                       hoverinfo='none'))
    if showCounts:
        avgOnly = True
        if avgOnly:
            countsFig.append(go.Scatter(y=arr(transpose(pic1Data)).flatten(), mode='markers',
                                        marker={'color': avgColor, 'size': 1}, legendgroup='avg', showlegend=False))
        countsHist.append(go.Histogram(x=atomCounts.flatten(), nbinsx=200, legendgroup='avg',
                                       showlegend=False, opacity=0.1, marker=dict(color=avgColor),
                                       xbins=dict(start=min(pic1Data.flatten()), end=max(pic1Data.flatten()))))
        d, _ = np.histogram(atomCounts.flatten(), bins=200)
        countsHist.append(go.Scatter(x=[0, max(d) / 2], y=[np.mean([thresh.t for thresh in initThresholds]), np.mean([thresh.t for thresh in initThresholds])],
                                     showlegend=False, mode='lines', line={'color': avgColor, 'width': 1},
                                     hoverinfo='none', legendgroup='avg'))
        # format and arrange plots. large grid is mostly to precisely place the histogram.
        n = None
        r = 'rowspan'
        c = 'colspan'
        fig = make_subplots(
            rows=3, cols=24, print_grid=False, horizontal_spacing=0.03, vertical_spacing=0.05,
            specs=[[{r: 3, c: 18}, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, {c: 4}, n, n, n,      {}, n],
                   [n,             n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, {c: 6}, n, n, n,      n,  n],
                   [n,             n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, {c: 3}, n, n, {c: 3}, n,  n]])
        traceSets = [mainPlot, avgFigs[0], avgFigs[1], initPopPlot, countsFig, countsHist]
        
        for mainLine in mainPlot:
            fig.add_trace(mainLine, 1, 1)
        for avgPart in avgFigs[0]:
            fig.add_trace(avgPart, 3, 19)
        for avgPart in avgFigs[1]:
            fig.add_trace(avgPart, 3, 22)
        for pop in initPopPlot:
            fig.add_trace(pop, 2, 19)
        for counts in countsFig:
            if not leanPlot:
                fig.add_trace(counts, 1, 19)
        for hist in countsHist:
            if not leanPlot:
                fig.add_trace(hist, 1, 23)
        fig['layout']['yaxis2'].update(title="Count", range=[min(pic1Data.flatten()), max(pic1Data.flatten())])
        fig['layout']['xaxis2'].update(range=[0, len(pic1Data[0].flatten())])
        fig['layout']['yaxis3'].update(range=[min(pic1Data.flatten()), max(pic1Data.flatten())],
                                       showticklabels=False)
        fig['layout']['xaxis3'].update(showticklabels=False)
        fig['layout']['yaxis4'].update(title="Initial Population %", range=[0, 1])
        fig['layout']['yaxis5'].update(title="Average Image")
    else:
        # format and arrange plots. large grid is mostly to precisely place the histogram.
        n = None
        r = 'rowspan'
        c = 'colspan'
        fig = make_subplots(
            rows=3, cols=24, print_grid=False, horizontal_spacing=0.03, vertical_spacing=0.05,
            specs=[[{r: 3, c: 18}, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, {c: 4}, n, n, n,      {}, n],
                   [n,             n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, {c: 6}, n, n, n,      n,  n],
                   [n,             n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, {c: 3}, n, n, {c: 3}, n,  n]])
        for mainLine in mainPlot:
            fig.add_trace(mainLine, 1, 1)
        for avgPart in avgFigs[0]:
            fig.add_trace(avgPart, 3, 19)
        for avgPart in avgFigs[1]:
            fig.add_trace(avgPart, 3, 22)
        for pop in initPopPlot:
            fig.add_trace(pop, 2, 19)
        for hist in countsHist:
            if not leanPlot:
                fig.add_trace(hist, 1, 19)
        fig['layout']['yaxis3'].update(title="Initial Population %", range=[0, 1])
        fig['layout']['yaxis5'].update(title="Average Image")
    fig['layout'].update(barmode='overlay', plot_bgcolor="rgb(10,10,10)", paper_bgcolor="rgb(0,0,0)")
    fig['layout']['yaxis1'].update(title=scanType + " %", range=[0, 1])
    fig['layout']['xaxis1'].update(title=str(keyName))
    iplot(fig)
    if savePlotlyFig:
        plotlyplot(fig, filename='plotly_plot.html')
    return key, transferData, transferErrs, initPopulation, fits, avgFit, genAvgs, genErrs, fitCharacters
Exemplo n.º 2
0
 figure=go.Figure(
     data = [
         go.Bar(
             x=df[df.Day=='Рабочий'].index,
             y=df[df.Day=='Рабочий'].Count,
             name='Рабочий'
         ),
         go.Bar(
             x=df[df.Day=='Выходной'].index,
             y=df[df.Day=='Выходной'].Count,
             name='Выходной'
         )
     ],
     layout = go.Layout(
         title='Количество выписок',
         xaxis=dict(
             rangeselector=dict(
                 buttons=list([
                     dict(
                         count=1,
                         label='1 месяц',
                         step='month',
                         stepmode='backward'
                     ),
                     dict(
                         count=6,
                         label='6 месяцев',
                         step='month',
                         stepmode='backward'
                     ),
                     dict(label='Год', step='all')
                 ])
             ),
             rangeslider=dict(visible=True),
             range=[
                 df.index.min()-pd.to_timedelta('1d'),
                 df.index.max()+pd.to_timedelta('1d')
             ],
             type='date',
         ),
         dragmode='pan'
     )
 ),
Exemplo n.º 3
0
def LineSurvey(
        spec,
        overlay=None,
        wunit="cm-1",
        Iunit="hitran",
        medium="air",
        cutoff=None,
        plot="S",
        lineinfo=["int", "A", "El"],
        barwidth=0.07,
        yscale="log",
        display=True,
        filename="line-survey.html",
        xunit=None,
        yunit=None,  # deprecated
):
    """ Plot Line Survey (all linestrengths above cutoff criteria) in Plotly (html)


    Parameters    
    ----------

    spec: Spectrum 
        result from SpectrumFactory calculation (see spectrum.py)

    overlay: tuple (w, I, [name], [units]), or list or tuples
        plot (w, I) on a secondary axis. Useful to compare linestrength with
        calculated / measured data 

    wunit: ``'nm'``, ``'cm-1'``
        wavelength / wavenumber units

    Iunit: ``'hitran'``, ``'splot'`` 
        Linestrength output units:

        - ``'hitran'``: (cm-1/(molecule/cm-2))
        - ``'splot'`` : (cm-1/atm)   (Spectraplot units [2]_)

        Note: if not None, cutoff criteria is applied in this unit.
        Not used if plot is not 'S'

    medium: ``'air'``, ``'vacuum'``
        show wavelength either in air or vacuum. Default ``'air'``

    plot: str
        what to plot. Default ``'S'`` (scaled line intensity). But it can be 
        any key in the lines, such as population (``'nu'``), or Einstein coefficient (``'Aul'``)

    lineinfo: list, or ``'all'``
        extra line information to plot. Should be a column name in the databank
        (s.lines). For instance: ``'int'``, ``'selbrd'``, etc... Default [``'int'``]

    Other Parameters
    ----------------

    display: boolean
        if True, open the image in a browser. Default ``True``. 

    filename: str
        filename to save .html 

    yscale: ``'log'``, ``'linear'``
        Default ``'log'``

    Returns
    -------

    Plot in Plotly. See Output in [1]_


    Examples
    --------

    An example using the :class:`~radis.lbl.factory.SpectrumFactory` to generate a spectrum::

        from radis import SpectrumFactory
        sf = SpectrumFactory(
                             wavenum_min=2380,
                             wavenum_max=2400,
                             mole_fraction=400e-6,
                             path_length=100,  # cm
                             isotope=[1],
                             db_use_cached=True) 
        sf.load_databank('HITRAN-CO2-TEST')
        s = sf.eq_spectrum(Tgas=1500)
        s.apply_slit(0.5)
        s.line_survey(overlay='radiance_noslit', barwidth=0.01)
        
    See the output in :ref:`Examples <label_examples>`
    
    References
    ----------

    .. [1] `RADIS Online Documentation (LineSurvey) <https://radis.readthedocs.io/en/latest/tools/line_survey.html>`__

    .. [2] `SpectraPlot <http://www.spectraplot.com/survey>`__


    """

    # Check inputs
    if xunit is not None:
        warn(DeprecationWarning("xunit replaced with wunit"))
        wunit = xunit
    if yunit is not None:
        warn(DeprecationWarning("yunit replaced with Iunit"))
        Iunit = yunit
    assert yscale in ["log", "linear"]

    try:
        spec.lines
        assert spec.lines is not None
    except (AttributeError, AssertionError):
        raise AttributeError(
            "Spectrum has no `lines`. Cant run line survey. If your code allows "
            + "it, recompute the spectrum with 'export_lines=True'")

    # Get input
    T = spec.conditions["Tgas"]
    P = spec.conditions["pressure_mbar"] / 1000  # bar1013.25 # atm
    Xi = spec.conditions["mole_fraction"]
    sp = spec.lines.copy()
    dbformat = spec.conditions["dbformat"]

    if not plot in list(sp.keys()):
        raise KeyError("Key {0} is not in line database: {1}".format(
            plot, list(sp.keys())))

    def hitran2splot(S):
        """ convert Linestrength in HITRAN units (cm-1/(molecules.cm-2)) to
        SpectraPlot units (cm-2/atm) """

        return S / (k_b * T) / 10

    # Parsers to get units and more details
    if dbformat == "hitran":
        columndescriptor = hitrancolumns
    elif dbformat == "cdsd-hitemp":
        columndescriptor = cdsdcolumns
    elif dbformat == "cdsd-4000":
        columndescriptor = cdsd4000columns

    # Apply cutoff, get ylabel
    if plot == "S":
        if Iunit == "hitran":
            if cutoff is None:
                cutoff = spec.conditions["cutoff"]
            sp = sp[(sp.S > cutoff)]
            Iunit_str = "cm-1/(molecule/cm-2)"
        elif Iunit == "splot":
            if cutoff is None:
                cutoff = spec.conditions["cutoff"]
                # if None, use default cutoff expressed in Hitran units
                sp = sp[(sp.S > cutoff)]
            else:
                sp["S"] = hitran2splot(sp.S)
                sp = sp[(sp.S > cutoff)]
            Iunit_str = "cm-1/atm"
        else:
            raise ValueError("Unknown Iunit: {0}".format(Iunit))
        ylabel = "Linestrength ({0})".format(Iunit_str)
    else:
        cutoff = 0
        try:  # to find units and real name (if exists in initial databank)
            _, _, name, unit = columndescriptor[plot]
            ylabel = "{0} - {1} [{2}]".format(name, plot, unit)
        except KeyError:
            ylabel = plot

    print(len(sp), "lines")
    if len(sp) == 0:
        raise ValueError("0 lines. Change your cutoff criteria?")

    # %% Plot - Plotly version

    def get_x(w):
        """ w (input) is supposed to be in vacuum wavenumbers in the 
        lines database """

        # Convert wavelength / wavenumber
        if wunit == "cm-1":
            x = w
        elif wunit == "nm":
            x = cm2nm(w)

            # Correct if requested medium is air
            if medium == "air":
                x = vacuum2air(x)
            elif medium == "vacuum":
                pass
            else:
                raise ValueError("Unknown medium: {0}".format(medium))
        else:
            raise ValueError("Unknown wunit: {0}".format(wunit))
        return x

    # Parse databank to get relevant information on each line
    # (one function per databank format)

    def get_label_hitran(row, details):
        """ 
        Todo
        -------

        replace with simple astype(str) statements and str operations

        ex:        
        > '['+df[locl].astype(str)+']('+df[globl].astype(str)+'->'+
        >     df[globu].astype(str)'+)'

        will be much faster! 
        """

        molecule = get_molecule(row.id)

        # Get global labels
        if molecule in HITRAN_CLASS1:
            label = "{molec}[iso{iso:.0f}] [{branch}{jl:.0f}]({vl:.0f})->({vu:.0f})".format(
                **dict([(k, row[k]) for k in ["vu", "vl", "jl", "iso"]] + [
                    ("molec", molecule),
                    ("branch", _fix_branch_format[row["branch"]]),
                ]))
        elif molecule in HITRAN_CLASS4:
            label = "{molec}[iso{iso:.0f}] [{branch}{jl:.0f}]({v1l:.0f}{v2l:.0f}`{l2l:.0f}`{v3l:.0f})->({v1u:.0f}{v2u:.0f}`{l2u:.0f}`{v3u:.0f})".format(
                **dict([(k, row[k]) for k in [
                    "v1u",
                    "v2u",
                    "l2u",
                    "v3u",
                    "v1l",
                    "v2l",
                    "l2l",
                    "v3l",
                    "jl",
                    "iso",
                ]] + [
                    ("molec", molecule),
                    ("branch", _fix_branch_format[row["branch"]]),
                ]))
        elif molecule in HITRAN_CLASS5:
            label = "{molec}[iso{iso:.0f}] [{branch}{jl:.0f}]({v1l:.0f}{v2l:.0f}`{l2l:.0f}`{v3l:.0f} {rl:.0f})->({v1u:.0f}{v2u:.0f}`{l2u:.0f}`{v3u:.0f} {ru:.0f})".format(
                **dict([(k, row[k]) for k in [
                    "v1u",
                    "v2u",
                    "l2u",
                    "v3u",
                    "v1l",
                    "v2l",
                    "l2l",
                    "v3l",
                    "rl",
                    "ru",
                    "jl",
                    "iso",
                ]] + [
                    ("molec", molecule),
                    ("branch", _fix_branch_format[row["branch"]]),
                ]))
        else:
            raise NotImplementedError(
                "No label for {0}. Please add it!".format(molecule))

        # Add details about some line properties
        for k in details:
            name, _, unit = details[k]
            if is_float(row[k]):
                label += "<br>{0} {1}: {2:.3g} {3}".format(
                    k, name, row[k], unit)
            else:
                label += "<br>{0} {1}: {2} {3}".format(k, name, row[k], unit)

        return label

    def get_label_cdsd(row, details):
        label = "CO2[iso{iso}] [{branch}{jl:.0f}](p{polyl:.0f}c{wangl:.0f}n{rankl:.0f})->(p{polyu:.0f}c{wangu:.0f}n{ranku:.0f})".format(
            **dict([(k, row[k]) for k in [
                "polyl",
                "wangl",
                "rankl",
                "polyu",
                "wangu",
                "ranku",
                "jl",
                "iso",
            ]] + [("branch", _fix_branch_format[row["branch"]])]))

        for k in details:
            name, _, unit = details[k]
            if is_float(row[k]):
                label += "<br>{0} {1}: {2:.3g} {3}".format(
                    k, name, row[k], unit)
            else:
                label += "<br>{0} {1}: {2} {3}".format(name, k, row[k], unit)

        return label

    def get_label_cdsd_hitran(row, details):
        label = "CO2[iso{iso}] [{branch}{jl:.0f}]({v1l:.0f}{v2l:.0f}`{l2l:.0f}`{v3l:.0f})->({v1u:.0f}{v2u:.0f}`{l2u:.0f}`{v3u:.0f})".format(
            **dict([(k, row[k]) for k in [
                "v1u",
                "v2u",
                "l2u",
                "v3u",
                "v1l",
                "v2l",
                "l2l",
                "v3l",
                "jl",
                "iso",
            ]] + [("branch", _fix_branch_format[row["branch"]])]))

        for k in details:
            name, _, unit = details[k]
            if is_float(row[k]):
                label += "<br>{0} {1}: {2:.3g} {3}".format(
                    k, name, row[k], unit)
            else:
                label += "<br>{0} {1}: {2} {3}".format(name, k, row[k], unit)

        return label

    def get_label_none(row):
        return "unknown databank format. \ndetails cant be read"

    # add extra info to label
    details = {}
    if columndescriptor:
        for k in lineinfo:
            if not k in sp.columns:
                raise KeyError(
                    "{0} not a {1} databank entry ({2} format)".format(
                        k, columndescriptor, dbformat.upper()))
            try:  # to find units and real name (if exists in initial databank)
                _, ktype, name, unit = columndescriptor[k]
                details[k] = (name, ktype, " [{0}]".format(unit))
            except:
                details[k] = ("", None, "")  # keep short name

    # Get label
    if dbformat == "hitran":
        sp["label"] = sp.apply(lambda r: get_label_hitran(r, details), axis=1)
    elif dbformat in ["cdsd-hitemp", "cdsd-4000"]:
        try:
            sp["label"] = sp.apply(lambda r: get_label_cdsd_hitran(r, details),
                                   axis=1)
        except KeyError:
            sp["label"] = sp.apply(lambda r: get_label_cdsd(r, details),
                                   axis=1)
    else:
        sp["label"] = sp.apply(get_label_none, axis=1)

    # from plotly.graph_objs import Scatter, Figure, Layout
    #
    l = [
        go.Bar(
            x=get_x(sp.shiftwav),
            y=sp[plot],
            text=sp.label,
            width=barwidth,
            name="linestrength",
        )
    ]

    if wunit == "nm":
        xlabel = "Wavelength (nm) [{0}]".format(medium)
    elif wunit == "cm-1":
        xlabel = "Wavenumber (cm-1)"
    else:
        raise ValueError("unknown wunit: {0}".format(wunit))

    if yscale == "log":
        plot_range = (
            int(np.log10(max(cutoff, sp[plot].min()))),
            int(np.log10(sp[plot].max())) + 1,
        )
    else:
        plot_range = (max(cutoff, sp[plot].min()), sp[plot].max() + 1)

    layout = go.Layout(
        title="Line Survey ({T}K, {P:.3f}bar, Mfrac={Xi:.3f})".format(**{
            "T": T,
            "P": P,
            "Xi": Xi
        }),
        hovermode="closest",
        xaxis=dict(title=xlabel, ),
        yaxis=dict(
            title=ylabel,
            # note: LaTeX doesnt seem to work in Offline mode yet.
            type=yscale,
            range=plot_range,
            titlefont=dict(color="#1f77b4"),
            tickfont=dict(color="#1f77b4"),
        ),
        showlegend=False,
    )

    # %% Add overlay
    def add_overlay(overlay):

        over_w = overlay[0]
        over_I = overlay[1]
        args = overlay[2:]
        over_name = args[0] if len(args) > 0 else "overlay"
        over_units = args[1] if len(args) > 1 else "a.u"

        l.append(
            go.Scatter(
                x=over_w,
                #                        y=spec.out[overlay],
                y=over_I,
                yaxis="y2",
                name=over_name,
            ))

        layout["yaxis2"] = dict(
            title="{0} ({1})".format(over_name.capitalize(),
                                     over_units),  # note: LaTeX doesnt seem to
            # work in Offline mode yet.
            overlaying="y",
            type="log",
            side="right",
            titlefont=dict(color="#ff7f0e"),
            tickfont=dict(color="#ff7f0e"),
        )

    if overlay is not None:

        if type(overlay) is not list:
            overlay = [overlay]

        for ov in overlay:
            add_overlay(ov)

    # %% Plot

    fig = go.Figure(data=l, layout=layout)
    py.plot(fig, filename=filename, auto_open=display)
Exemplo n.º 4
0
print('termino for test2')
elapsed_time = time() - start_time
print("Elapsed time: %.10f seconds." % elapsed_time)


trace1 = go.Scatter3d(
    x=x,
    y=y,
    z=z,
    mode='markers',
    marker=dict(
        size=2,
        #color=z,                # set color to an array/list of desired values
        #colorscale='Viridis',   # choose a colorscale
        opacity=0.8
    )
)

data = [trace1]
layout = go.Layout(
    margin=dict(
        l=0,
        r=0,
        b=0,
        t=0
    )
)
fig = go.Figure(data=data, layout=layout)
plot(fig, filename='3d-scatter-colorscale')
    tickwidth=2
)

doslayout = go.Layout(
    title="<b> Density of states of AlEuO3 <b>",
    titlefont=dict(
        size=26,
        family='Times New Roman'
    ),
    xaxis=dosxaxis,
    yaxis=dosyaxis,
    width=900,
    height=600
)

dosfig = go.Figure(data=dosdata, layout=doslayout)
dosfig.update_layout(legend=dict(
    x=0.287,
    y=0.76,
    traceorder="normal",
    font=dict(
        family="Times New Roman",
        size=18,
        color='black'
    ),
    bgcolor='LightSteelBlue',  # set backgroud color
    bordercolor='yellow',  # set border color 框线颜色
    borderwidth=2,
))
plot_url = pltly.plot(dosfig, filename="DOS_AlEuO3", auto_open=True)
print(tls.get_embed(plot_url))
# In[1]:

# In[152]:

# ** Verifique o cabeçalho do DataFrame. **

# In[156]:

# ** Consultando as notas de aula, crie um plot de Choropleth do consumo de energia para países usando o dicionário de dados e layout. **

# In[ ]:

# In[ ]:

choromap = go.Figure(data=[data], layout=layout)
iplot(choromap, validate=False)

# ##  Choropleth EUA
#
# ** Importe o arquivo csv 2012_Election_Data usando pandas. **

# In[109]:

# ** Verifique o cabeçalho do DataFrame. **

# In[110]:

# ** Agora crie um gráfico que exiba a idade da população votante (Voting-Age Population, VAP) por estado. Se você quiser mais jogar com outras colunas, certifique-se de considerar seu tipo de dados. O VAP já foi transformado em float para você. **

# In[120]:
Exemplo n.º 7
0
Arquivo: app.py Projeto: apanchot/test
def plots(n_clicks, cities, indicator):

    ############################################First Bar Plot##########################################################
    data_bar = []

    new_selection = selected_cities.loc[cities,:].sort_values(by=[indicator])


    x_bar = new_selection.index
    y_bar = new_selection[indicator]

    data_bar.append(dict(type='bar', x=x_bar, y=y_bar, name=indicator))

    layout_bar = dict(title=dict(text=indicator.title() + ' per City'),
                  yaxis=dict(title=indicator.title() + ' Value'),
                  paper_bgcolor='#f9f9f9'
                  )

    #############################################Second ScatterGeo######################################################

    data = [[distance(i, j) for j in new_selection.index] for i in new_selection.index]

    run = ga_search(data)

    def path(x):
        best_fitness_aux = run.loc[x, 'Fittest'].replace(',', '').replace('[', '').replace(']', '').split(' ')
        path_best_fitness = [int(i) for i in best_fitness_aux]
        path_best_fitness = path_best_fitness + [path_best_fitness[0]]
        return path_best_fitness

    generation = lambda x: ['Generation_' + str(run.loc[x, 'Generation'])] * len(path(x))
    total_distance = lambda x: [run.loc[x, 'Fitness']] * len(path(x))

    all_path = []
    all_generation = []
    all_distances = []
    for i in run.loc[:, 'Generation']:
        all_path = all_path + path(i)
        all_generation = all_generation + generation(i)
        all_distances = all_distances + total_distance(i)

    all_generation = pd.Series(all_generation)
    all_path = pd.Series(all_path)
    all_distances = pd.Series(all_distances)

    x_coordinate = [new_selection.iloc[i, 0] for i in all_path]
    y_coordinate = [new_selection.iloc[i, 1] for i in all_path]
    name_city = [new_selection.index[i] for i in all_path]
    x_coordinate = pd.Series(x_coordinate)
    y_coordinate = pd.Series(y_coordinate)
    name_city = pd.Series(name_city)

    df = pd.concat([all_generation, all_path, all_distances, name_city, x_coordinate, y_coordinate], axis=1)
    df.columns = ['generation', 'city', 'distance', 'name_city', 'x_coordinate', 'y_coordinate']

    df['norm_distance'] = (df['distance'] - df['distance'].min()) / (df['distance'].max() - df['distance'].min())

    map_data=[go.Scattergeo(lat=df.loc[df.loc[:,"generation"] == 'Generation_0',"x_coordinate"] , 
                     lon=df.loc[df.loc[:,"generation"] == 'Generation_0',"y_coordinate"] ,
                     hoverinfo = 'text',
                     text = df.loc[df.loc[:,"generation"] == 'Generation_0',"name_city"],
                     mode="lines+markers",
                     line=dict(width=1, color="blue"),
                     marker=dict(size=4, color="red"))]
    
    map_layout=go.Layout(
        title_text="Optimized World Tour", hovermode="closest",
        updatemenus=[dict(type="buttons",
                          buttons=[dict(label="Play",
                                        method="animate",
                                        args=[None]),
                                   dict(label="Pause",
                                        method="animate",
                                        args=[None])])])
    
    map_frames=[go.Frame(
        data=[go.Scattergeo(lat=df.loc[df.loc[:,"generation"] == k,"x_coordinate"] , 
                     lon=df.loc[df.loc[:,"generation"] == k,"y_coordinate"] ,
                     text = df.loc[df.loc[:,"generation"] == k,"name_city"],
                     mode="lines+markers",
                     line=dict(width=((df.loc[df.loc[:,"generation"] == k,"norm_distance"].iloc[0])+0.1)*8, color="white"),
                     marker=dict(size=40,
                                 colorscale='Blues',
                                 cmin=0,
                                 color=df['distance'],
                                 cmax=df['distance'].max(),
                                 colorbar_title="Incoming flights<br>February 2011"
                                 ))])

        for k in df.loc[:,"generation"].unique()]

    return go.Figure(data=data_bar, layout=layout_bar), \
           go.Figure(data=map_data, layout=map_layout, frames=map_frames)
Exemplo n.º 8
0
def PCA_sumplot(Z,
                Z_chose,
                Theta_record,
                pca_obj,
                fig_dens_I=[],
                new_data=[],
                Ncols=2,
                PC_select=2,
                height=600,
                width=1000):
    titles = [
        'probab', 'Ave. PC coordinates among kde sampled theta vectors',
        'loadings of PC {}'.format(PC_select + 1)
    ]

    fig_subplots = tools.make_subplots(rows=int(len(titles) / float(Ncols)) +
                                       (len(titles) % Ncols > 0),
                                       cols=Ncols,
                                       subplot_titles=tuple(titles))
    for gp in range(len(titles)):
        pos1 = int(float(gp) / Ncols) + 1
        pos2 = gp - (pos1 - 1) * Ncols + 1

        title = titles[gp]

        if gp == 0:
            zprime = Z[Z_chose]
            bandwidth = estimate_bandwidth(zprime, quantile=0.2, n_samples=500)

            X_plot = np.linspace(-2, 8, 100)[:, np.newaxis]

            kde_plot = KernelDensity(kernel='gaussian',
                                     bandwidth=bandwidth).fit(zprime)
            log_dens = kde_plot.score_samples(X_plot)

            trace = go.Scatter(x=X_plot[:, 0],
                               y=np.exp(log_dens),
                               mode='lines',
                               fill='tozeroy',
                               line=dict(color='red', width=2))

            fig_subplots.append_trace(trace, pos1, pos2)

            if len(fig_dens_I):
                fig_subplots.append_trace(fig_dens_I[0], pos1, pos2)

        if gp == 1:
            feat_sum = np.sum(new_data, axis=0)
            trace = go.Bar(
                x=['PC {}'.format(x + 1) for x in range(new_data.shape[1])],
                y=feat_sum,
                marker=dict(color='rgb(0,0,205)'))
            fig_subplots.append_trace(trace, pos1, pos2)

            fig_subplots['layout']['yaxis' + str(gp + 1)].update(title='mean')

        if gp == 2:

            times_data = [
                list(Theta_record[x]['comb'][:, 0])
                for x in Theta_record.keys()
            ]
            times_data = np.array(times_data)
            times_av = np.mean(times_data, axis=0)
            times_av = [int(x) for x in times_av / 1000]
            times_av = ['{}k y'.format(x) for x in times_av]

            Xcomps = pca_obj.components_

            trace = go.Bar(x=times_av,
                           y=Xcomps[PC_select, :],
                           marker=dict(color='rgb(0,0,205)'))

            fig_subplots.append_trace(trace, pos1, pos2)

            fig_subplots['layout']['yaxis' +
                                   str(gp + 1)].update(title='eigen value')

    fig_subplots['layout'].update(height=height, width=width)

    layout = go.Layout(title=title)

    fig = go.Figure(data=fig_subplots, layout=layout)
    iplot(fig_subplots)
Exemplo n.º 9
0
def plot_rec_InfSites(point_up,
                      root_lib,
                      funk,
                      titles,
                      range_theta,
                      height=500,
                      width=900):
    Ncols = 1

    fig_subplots = tools.make_subplots(rows=int(len(titles) / float(Ncols)) +
                                       (len(titles) % Ncols > 0),
                                       cols=Ncols,
                                       subplot_titles=tuple(titles))

    for gp in range(len(titles)):

        pos1 = int(float(gp) / Ncols) + 1
        pos2 = gp - (pos1 - 1) * Ncols + 1

        title = titles[gp]

        Inf_sites_est = []
        there = []

        runUp_use = funk[gp]

        t1 = time.time()

        for x in range_theta:

            ## run up the tree.
            Browse = runUp_use(point_up,
                               root_lib,
                               layer=0,
                               start=0,
                               Theta=x,
                               prob_vec=[])
            probe_rec = sum(Browse)

            Inf_sites_est.append(probe_rec)
            there.append(x)

        t2 = time.time()
        tscale = 's'
        tpass = t2 - t1

        if tpass > 600:
            tpass = tpass / 60
            tscale = 'm'

        tpass = round(tpass, 3)

        trace1 = go.Scatter(y=Inf_sites_est,
                            x=there,
                            mode='markers',
                            name=titles[gp])

        fig_subplots.append_trace(trace1, pos1, pos2)

        fig_subplots['layout']['yaxis' + str(gp + 1)].update(title='P')
        fig_subplots['layout']['yaxis' + str(gp + 1)].update(
            range=[0, max(Inf_sites_est) + max(Inf_sites_est) / 10])
        fig_subplots['layout']['xaxis' + str(gp + 1)].update(
            title='theta - ts {} {}'.format(tpass, tscale))

    layout = go.Layout(title=title, )

    fig = go.Figure(data=fig_subplots, layout=layout)

    fig['layout'].update(height=height, width=width)

    iplot(fig)
Exemplo n.º 10
0
def plot_InfSites_gens(mrcas,
                       point_up,
                       root_lib,
                       range_theta,
                       Theta=1,
                       mut_rate=9e-8,
                       height=500,
                       width=900):

    from structure_tools.Coal_tools import tree_descent_gen

    hap_frame = [[''.join([str(x) for x in z])] for z in mrcas]
    hap_frame = list(range(len(mrcas)))

    hap_frame = pd.DataFrame(hap_frame, columns=['hap_id'])
    hap_frame["hap"] = [''.join([str(x) for x in z]) for z in mrcas]

    Ncols = 1
    titles = [''.join([str(x) for x in y]) for y in mrcas]

    fig = []
    vals = []

    for gp in range(len(titles)):

        title = titles[gp]

        sink, starters = get_sinks(mrcas[gp], root_lib, point_up)

        t1 = time.time()
        if len(starters):

            #node_weigths, paths_reverse = tree_descent(root_lib,point_up,sink,init= starters,Theta= thet)

            #probe_rec= node_weigths[0][0]

            node_weigths, paths_reverse, node_bins, paths_vector = tree_descent_gen(
                root_lib, point_up, sink, Theta=Theta, mu=mut_rate)

            paths_vector = paths_reverse[0][0]
            average_gen = np.mean(paths_vector)

            vals.append(average_gen)

    sort_vals = np.argsort(vals)
    vals = [vals[x] for x in sort_vals]
    titles = [titles[x] for x in sort_vals]

    fig = [go.Bar(x=['hap: {}'.format(x) for x in range(len(titles))], y=vals)]

    layout = go.Layout(title='gens until first hap appearence',
                       barmode='group',
                       xaxis=dict(title='hap'),
                       yaxis=dict(title='Gen'))

    Figure = go.Figure(data=fig, layout=layout)

    hap_frame['t'] = [round(c, 3) for c in vals]
    hap_frame = hap_frame.sort_values('t')

    return hap_frame, Figure
Exemplo n.º 11
0
def theta_PCAms_plot(data_combs, Z, N_samp=50, n_comp=4, kernel='gaussian'):
    ## Perform PCA
    pca = PCA(n_components=n_comp, whiten=False, svd_solver='randomized')
    ##

    feats_combs = pca.fit_transform(data_combs)

    fig_pca_combs = [
        go.Scatter3d(x=feats_combs[:, 0],
                     y=feats_combs[:, 1],
                     z=feats_combs[:, 2],
                     mode='markers',
                     marker=dict(color=Z.reshape(1, -1)[0],
                                 colorscale='Viridis'))
    ]

    ###
    ###
    Z_chose = list(Z.reshape(1, -1)[0])
    Z_chose = np.argsort(Z_chose)

    Z_chose = Z_chose[(len(Z_chose) - 15):]
    #Z_chose= [x for x in range(len(Z_vec)) if Z_vec[x] >= 1]

    Z_high = feats_combs[Z_chose]

    print(Z_high.shape)
    params = {'bandwidth': np.linspace(0.1, 2, 20)}
    grid = GridSearchCV(KernelDensity(kernel=kernel), params, cv=5, iid=False)
    grid.fit(Z_high)

    kde = grid.best_estimator_
    new_data = kde.sample(N_samp, random_state=1)

    fig_pca_combs.append(
        go.Scatter3d(x=new_data[:, 0],
                     y=new_data[:, 1],
                     z=new_data[:, 2],
                     mode='markers'))

    layout = go.Layout(scene=dict(
        xaxis=dict(
            backgroundcolor="rgb(72,61,139)",
            gridcolor="rgb(255, 255, 255)",
            showbackground=False,
            showgrid=False,
            zerolinecolor="rgb(255, 255, 255)",
        ),
        yaxis=dict(backgroundcolor="rgb(72,61,139)",
                   gridcolor="rgb(255, 255, 255)",
                   showbackground=False,
                   showgrid=False,
                   nticks=0,
                   zerolinecolor="rgb(255, 255, 255)"),
        zaxis=dict(
            backgroundcolor="rgb(72,61,139)",
            gridcolor="rgb(255, 255, 255)",
            showbackground=False,
            showgrid=False,
            zerolinecolor="rgb(255, 255, 255)",
        ),
    ))

    Figure = go.Figure(data=fig_pca_combs, layout=layout)

    return Figure, new_data, feats_combs, pca, Z_chose
Exemplo n.º 12
0
    def activate(self):

        filename, _ = compat.getsavefilename(parent=self.viewer,
                                             basedir="plot.html")

        # when vispy viewer is in "native aspect ratio" mode, scale axes size by data
        if self.viewer.state.native_aspect == True:
            width = self.viewer.state.x_max - self.viewer.state.x_min
            height = self.viewer.state.y_max - self.viewer.state.y_min
            depth = self.viewer.state.z_max - self.viewer.state.z_min

        # otherwise, set all axes to be equal size
        else:
            width = 1200  # this 1200 size is arbitrary, could change to any width; just need to scale rest accordingly
            height = 1200
            depth = 1200

        # set the aspect ratio of the axes, the tick label size, the axis label sizes, and the axes limits
        layout = go.Layout(
            margin=dict(r=50, l=50, b=50, t=50),
            width=1200,
            scene=dict(
                xaxis=dict(title=self.viewer.state.x_att.label,
                           titlefont=dict(family=DEFAULT_FONT,
                                          size=20,
                                          color='black'),
                           showticklabels=True,
                           backgroundcolor='white',
                           tickfont=dict(family=DEFAULT_FONT,
                                         size=12,
                                         color='black'),
                           range=[0, self.viewer.state.resolution]),
                yaxis=dict(
                    title=self.viewer.state.y_att.label,
                    titlefont=dict(family=DEFAULT_FONT, size=20,
                                   color='black'),
                    range=[0, self.viewer.state.resolution],
                    showticklabels=True,
                    backgroundcolor='white',
                    tickfont=dict(family=DEFAULT_FONT, size=12, color='black'),
                ),
                zaxis=dict(
                    title=self.viewer.state.z_att.label,
                    titlefont=dict(family=DEFAULT_FONT, size=20,
                                   color='black'),
                    range=[0, self.viewer.state.resolution],
                    showticklabels=True,
                    backgroundcolor='white',
                    tickfont=dict(family=DEFAULT_FONT, size=12, color='black'),
                ),
                aspectratio=dict(
                    x=1 * self.viewer.state.x_stretch,
                    y=height / width * self.viewer.state.y_stretch,
                    z=depth / width * self.viewer.state.z_stretch),
                aspectmode='manual',
            ),
        )

        #set up function that returns values of cube at different pixel positions in the fixed resolution grid
        f = lambda x, y, z, datacube: datacube[z, y, x]

        bounds = [(self.viewer.state.z_min, self.viewer.state.z_max,
                   self.viewer.state.resolution),
                  (self.viewer.state.y_min, self.viewer.state.y_max,
                   self.viewer.state.resolution),
                  (self.viewer.state.x_min, self.viewer.state.x_max,
                   self.viewer.state.resolution)]

        #generate array of vertices at fixed resolution
        X, Y, Z = np.mgrid[0:self.viewer.state.resolution,
                           0:self.viewer.state.resolution,
                           0:self.viewer.state.resolution]

        data = []
        for layer_state in self.viewer.state.layers:

            #check if subset object
            if isinstance(layer_state.layer,
                          glue.core.subset_group.GroupedSubset):
                subcube = layer_state.layer.data.compute_fixed_resolution_buffer(
                    target_data=self.viewer.state.reference_data,
                    bounds=bounds,
                    subset_state=layer_state.layer.subset_state)
                datacube = layer_state.layer.data.compute_fixed_resolution_buffer(
                    target_data=self.viewer.state.reference_data,
                    bounds=bounds,
                    target_cid=layer_state.attribute)
                datacube = subcube * datacube

                for i in range(0, len(self.viewer.state.layers)):
                    if self.viewer.state.layers[
                            i].layer is layer_state.layer.data:
                        isomin = self.viewer.state.layers[i].vmin
                        isomax = self.viewer.state.layers[i].vmax

            #otherwise a data object
            else:
                datacube = layer_state.layer.compute_fixed_resolution_buffer(
                    target_data=self.viewer.state.reference_data,
                    bounds=bounds,
                    target_cid=layer_state.attribute)
                isomin = layer_state.vmin
                isomax = layer_state.vmax

            #fetch values of cube at different coordinate combination
            values = f(X.flatten().astype(int),
                       Y.flatten().astype(int),
                       Z.flatten().astype(int), datacube.copy())

            voltrace = go.Volume(
                x=X.flatten().astype(int),
                y=Y.flatten().astype(int),
                z=Z.flatten().astype(int),
                value=values.flatten(),
                flatshading=True,
                opacity=0.2,
                isomin=isomin,
                showscale=False,
                isomax=isomax,
                colorscale=[[0, 'white'], [1., layer_state.color]],
                opacityscale='max',
                reversescale=False,
                surface=dict(show=True, count=25),
                spaceframe=dict(show=True),  #,
                contour=dict(show=False, width=4))
            data.append(voltrace)

        fig = go.Figure(data=data, layout=layout)

        plot(fig, filename=filename, auto_open=False)
def sent_cust(target):

    my_path = os.path.abspath(os.path.dirname('__file__'))
    path_in_ngrams = os.path.join(my_path, "../data/cpickle/")

    path_in_pos = os.path.join(my_path, "../data/pos/")

    import colorlover as cl
    from IPython.display import HTML

    colors_all = cl.scales['11']["qual"]["Set3"]

    colors_all.extend(cl.scales['11']["qual"]["Paired"])

    colors_all.extend(cl.scales['11']["qual"]["Set3"])

    import plotly.plotly as py
    import plotly.graph_objs as go

    data = []


    my_path = os.path.abspath(os.path.dirname('__file__'))
    path_in_sent = os.path.join(my_path, "data/yelp_sentiment/")

    dat = pickle.load(open(path_in_sent + "yelp_sent.p", "rb"))
    dt = {}
    mata = []
    for aes, dars in dat.items():
        i = -1
        data = []
        dars = (dars / len(dars.columns))/4*100
        for col in dars.columns:
            i = i + 1

            trace = go.Bar(
                y=list(dars.index), x=list(dars[col]),
                name=str(col),
                orientation='h',
                legendgroup=str(aes),
                marker=dict(color=colors_all[i],
                            line=dict(color=colors_all[i],
                                      width=1)))
            data.append(trace)
            mata.append(trace)

        layout = go.Layout(
            barmode='stack',
            bargap=0.2,
            title="Service, Food, Preparation and Location Sentiment <br>"
                  "(Please Use Legend To Toggle)",
            #width=500,
            height=500,
            xaxis=dict(
                showgrid=False,
                zeroline=False,
                showline=False,

            ),
            yaxis=dict(
                showgrid=False,
                zeroline=False,
                showline=False,
            ),
        )

        fig = go.Figure(data=data, layout=layout)
        # py.iplot(fig, filename='marker-h-bar')
        dt[aes] = fig

    fig = go.Figure(data=mata, layout=layout)
    dt["full"] = fig


    ### For Quarter:

    my_path = os.path.abspath(os.path.dirname('__file__'))
    path_in_sent = os.path.join(my_path, "data/yelp_sentiment/")

    dat = pickle.load(open(path_in_sent + "yelp_sent.p", "rb"))
    ke = []

    i = -1

    for aes, dars in dat.items():
        i = i + 1
        ke.append(aes)
        if i == 0:
            va = pd.DataFrame(index=dars.index)
        va = pd.concat((va, dars), axis=1)

    ra = va[va.index.str.contains("-TQ")]

    df_rank = pd.DataFrame()
    for col in ra.columns:
        df_rank[col] = ra[col].rank(ascending=0)

    df_rank = df_rank.astype(int)

    bjri_tq = va[va.index == (target + "-TQ ")]
    # .iloc[0,:]
    # .sort_values()

    bjri_tq = bjri_tq.T

    bjri_tq_rank = df_rank[df_rank.index == (target + "-TQ ")]

    bjri_tq["rank"] = bjri_tq_rank.T

    bjri_tq = bjri_tq.sort_values((target + "-TQ "), ascending=True)


    trace0 = go.Bar(
        x=bjri_tq[(target + "-TQ ")].values,
        y=bjri_tq.index,
        orientation='h',
        text=["Overall Position: " + str(s) for s in list(bjri_tq["rank"].values)],
        marker=dict(
            color='rgb(158,202,225)',
            line=dict(
                color='rgb(8,48,107)',
                width=1.5,
            )
        ),
        opacity=0.6
    )

    data = [trace0]
    layout = go.Layout(

    annotations=[dict(

                    showarrow=False,
                    text =str(int(bjri_tq[(target + "-TQ ")].mean()*100)) +'/100',
                    #xanchor="right",
                    x=1,
                    y=3,
                    xref='x',
                    yref='y',
                    opacity=0.1,
                    font=dict(
                        color="black",
                        size=30
                    ),)],

        height=800,
        xaxis=dict(
            showgrid=False,
            zeroline=False,
            showline=False,



        ),

        yaxis=dict(
            showgrid=False,
            zeroline=False,
            showline=False,
            # tickangle=45,
            tickfont=dict(
                size=10),

        ),
        margin=go.Margin(
            l=90,
            r=0,
            b=0,
            t=70,
            pad=0
        ),
        title=bjri_tq.columns[0] + ' Sentiment Report',
    )

    fig = go.Figure(data=data, layout=layout)


    dt["quarter"] = fig



    ba = va[va.index.str.contains("-TQ")].T.sum()

    ba.index = [s[:-4] for s in list(ba.index)]

    ba = ba/len(va.columns)*100

    trace1 = go.Bar(
        x=ba.index,
        y=ba.values,
        marker=dict(
            color='Lightgrey',
            line=dict(
                color='rgb(8,48,107)',
                width=1.5,
            )
        ),
        opacity=1
    )

    layout = go.Layout(
        height=150,
    xaxis=dict(
        showgrid=False,
        zeroline=False,
        showline=False,
    ),
    yaxis=dict(
        showgrid=False,
        zeroline=False,
        showline=False,),

    margin=go.Margin(
        l=0,
        r=0,
        b=23,
        t=20,
        pad=0
    ),
    )
    data = [trace1]
    fig_national = go.Figure(data=data, layout=layout)


    dt["small"] = fig_national

    return dt
Exemplo n.º 14
0
def evolution_bars_plot(df):
    """FIXME! briefly describe function

    :param df:
    :returns:
    :rtype:

    """
    x = df['Date'].values

    fig = go.Figure()

    config = {'displayModeBar': True}

    fig.add_traces(data=[
        go.Bar(name='Décès', x=x, y=df['Décès'].values, marker_color='red'),
        go.Bar(name='Guéris',
               x=x,
               y=df['Guéris'].values,
               marker_color='darkgreen'),
        go.Bar(name='Cas hospitalisés',
               x=x,
               y=df['Cas hospitalisés'],
               marker_color='gold')
    ])

    fig.add_trace({
        'x': df['Date'],
        'y': df['Cas confirmés'],
        'name': 'Cas confirmés'
    })

    fig.add_traces(data=[
        go.Bar(name='Nouveaux décès',
               x=x,
               y=df['Nouveaux décès'].values,
               marker_color='red',
               visible=False),
        go.Bar(name='Nouveaux guéris',
               x=x,
               y=df['Nouveaux guéris'].values,
               marker_color='darkgreen',
               visible=False),
        go.Bar(name='Nouveaux cas',
               x=x,
               y=df['Nouveaux cas'],
               marker_color='gold',
               visible=False)
    ])

    fig.update_yaxes(automargin=True)

    # Add dropdown
    fig.update_layout(
        updatemenus=[
            dict(type='dropdown',
                 active=0,
                 buttons=list([
                     dict(
                         label="Cumul",
                         method="update",
                         args=[{
                             "visible":
                             [True, True, True, True, False, False, False]
                         }],
                     ),
                     dict(
                         label="Par jour",
                         method="update",
                         args=[{
                             "visible":
                             [False, False, False, False, True, True, True]
                         }, {
                             "title":
                             'Suivi journalier du Covid-19 en Guinée',
                         }],
                     )
                 ]),
                 direction="down",
                 showactive=True,
                 x=0.01,
                 xanchor="center",
                 y=1.02,
                 yanchor='middle',
                 bgcolor='darkred',
                 font=dict(color='gray', size=14)),
        ],
        template='plotly_dark',
        barmode='stack',
        hovermode='x',
        xaxis_tickangle=-60,
        legend_orientation="h",
        legend=dict(x=0, y=-0.3),
        margin=dict(t=40, b=0, l=25, r=3),
        title=dict(text='Évolution du Covid-19 en Guinée : données cumulées',
                   x=0.5,
                   y=0.1,
                   font=dict(size=12.5)),
    )

    return fig
Exemplo n.º 15
0
def update_graph(datePicked, selectedData, selectedLocation):
    zoom = 12.0
    latInitial = 40.7272
    lonInitial = -73.991251
    bearing = 0

    if selectedLocation:
        zoom = 15.0
        latInitial = list_of_locations[selectedLocation]["lat"]
        lonInitial = list_of_locations[selectedLocation]["lon"]

    date_picked = dt.strptime(datePicked, "%Y-%m-%d")
    monthPicked = date_picked.month - 4
    dayPicked = date_picked.day - 1
    listCoords = getLatLonColor(selectedData, monthPicked, dayPicked)

    return go.Figure(
        data=[
            # Data for all rides based on date and time
            Scattermapbox(
                lat=listCoords["Lat"],
                lon=listCoords["Lon"],
                mode="markers",
                hoverinfo="lat+lon+text",
                text=listCoords.index.hour,
                marker=dict(
                    showscale=True,
                    color=np.append(np.insert(listCoords.index.hour, 0, 0),
                                    23),
                    opacity=0.5,
                    size=5,
                    colorscale=[
                        [0, "#F4EC15"],
                        [0.04167, "#DAF017"],
                        [0.0833, "#BBEC19"],
                        [0.125, "#9DE81B"],
                        [0.1667, "#80E41D"],
                        [0.2083, "#66E01F"],
                        [0.25, "#4CDC20"],
                        [0.292, "#34D822"],
                        [0.333, "#24D249"],
                        [0.375, "#25D042"],
                        [0.4167, "#26CC58"],
                        [0.4583, "#28C86D"],
                        [0.50, "#29C481"],
                        [0.54167, "#2AC093"],
                        [0.5833, "#2BBCA4"],
                        [1.0, "#613099"],
                    ],
                    colorbar=dict(
                        title="Time of<br>Day",
                        x=0.93,
                        xpad=0,
                        nticks=24,
                        tickfont=dict(color="#d8d8d8"),
                        titlefont=dict(color="#d8d8d8"),
                        thicknessmode="pixels",
                    ),
                ),
            ),
            # Plot of important locations on the map
            Scattermapbox(
                lat=[list_of_locations[i]["lat"] for i in list_of_locations],
                lon=[list_of_locations[i]["lon"] for i in list_of_locations],
                mode="markers",
                hoverinfo="text",
                text=[i for i in list_of_locations],
                marker=dict(size=8, color="#ffa0a0"),
            ),
        ],
        layout=Layout(
            autosize=True,
            margin=go.layout.Margin(l=0, r=35, t=0, b=0),
            showlegend=False,
            mapbox=dict(
                accesstoken=mapbox_access_token,
                center=dict(lat=latInitial,
                            lon=lonInitial),  # 40.7272  # -73.991251
                style="dark",
                bearing=bearing,
                zoom=zoom,
            ),
            updatemenus=[
                dict(
                    buttons=([
                        dict(
                            args=[{
                                "mapbox.zoom": 12,
                                "mapbox.center.lon": "-73.991251",
                                "mapbox.center.lat": "40.7272",
                                "mapbox.bearing": 0,
                                "mapbox.style": "dark",
                            }],
                            label="Reset Zoom",
                            method="relayout",
                        )
                    ]),
                    direction="left",
                    pad={
                        "r": 0,
                        "t": 0,
                        "b": 0,
                        "l": 0
                    },
                    showactive=False,
                    type="buttons",
                    x=0.45,
                    y=0.02,
                    xanchor="left",
                    yanchor="bottom",
                    bgcolor="#323130",
                    borderwidth=1,
                    bordercolor="#6d6d6d",
                    font=dict(color="#FFFFFF"),
                )
            ],
        ),
    )
Exemplo n.º 16
0
def plot_covariance_returns_correlation(correlation, title):
    config = helper.generate_config()
    graph_path = 'graphs/{}.html'.format(_sanatize_string(title))
    data = []

    dendro_top = ff.create_dendrogram(correlation, orientation='bottom')
    for i in range(len(dendro_top['data'])):
        dendro_top['data'][i]['yaxis'] = 'y2'
    data.extend(dendro_top['data'])

    dendro_left = ff.create_dendrogram(correlation, orientation='right')
    for i in range(len(dendro_left['data'])):
        dendro_left['data'][i]['xaxis'] = 'x2'
    data.extend(dendro_left['data'])

    heatmap_hover_text = _generate_hover_text(correlation.index,
                                              correlation.columns,
                                              correlation.values, 'Ticker 2',
                                              'Ticker 1', 'Correlation')
    heatmap_trace = go.Heatmap(x=dendro_top['layout']['xaxis']['tickvals'],
                               y=dendro_left['layout']['yaxis']['tickvals'],
                               z=correlation.values,
                               zauto=False,
                               zmax=1.0,
                               zmin=-1.0,
                               text=heatmap_hover_text,
                               hoverinfo='text')
    data.append(heatmap_trace)

    xaxis1_layout = {
        'showgrid': False,
        'showline': False,
        'zeroline': False,
        'showticklabels': False,
        'ticks': ""
    }
    xaxis2_layout = {
        'showgrid': False,
        'zeroline': False,
        'showticklabels': False
    }

    layout = go.Layout(title=title, showlegend=False, width=800, height=800)

    figure = go.Figure(data=data, layout=layout)
    figure['layout']['xaxis'].update({'domain': [.15, 1]})
    figure['layout']['xaxis'].update(xaxis1_layout)
    figure['layout']['yaxis'].update({'domain': [0, .85]})
    figure['layout']['yaxis'].update(xaxis1_layout)

    figure['layout']['xaxis2'].update({'domain': [0, .15]})
    figure['layout']['xaxis2'].update(xaxis2_layout)
    figure['layout']['yaxis2'].update({'domain': [.825, .975]})
    figure['layout']['yaxis2'].update(xaxis2_layout)

    offline_py.plot(figure,
                    config=config,
                    filename=graph_path,
                    auto_open=False)
    display(
        HTML(
            'The graph for {} is too large. You can view it <a href="{}" target="_blank">here</a>.'
            .format(title, graph_path)))
Exemplo n.º 17
0
    def plot_evaluation_metrics(self,
                                metric_dict: Dict,
                                config_names: List = None,
                                xlabel: str = None,
                                ylabel: str = "Metric value",
                                title: str = None,
                                showlegend: bool = True):
        """Returns a barplot of the train and test values of ``metric_dict`` of ``config_names``.
        Value of a metric for all ``config_names`` are plotted as a grouped bar.
        Train and test values of a metric are plot side-by-side for easy comparison.

        Parameters
        ----------
        metric_dict : `dict` [`str`, `callable`]
            Evaluation metrics to compute. Same as
            `~greykite.framework.framework.benchmark.benchmark_class.BenchmarkForecastConfig.get_evaluation_metrics`.
            To get the best visualization, keep number of metrics <= 2.
        config_names : `list` [`str`], default None
            Which config results to plot. A list of config names.
            If None, uses all the available config keys.
        xlabel : `str` or None, default None
            x-axis label.
        ylabel : `str` or None, default "Metric value"
            y-axis label.
        title : `str` or None, default None
            Plot title.
        showlegend : `bool`, default True
            Whether to show the legend.

        Returns
        -------
         fig : `plotly.graph_objs.Figure`
            Interactive plotly bar plot.
        """
        evaluation_metrics_df = self.get_evaluation_metrics(
            metric_dict=metric_dict, config_names=config_names)

        # This function groups by config name
        evaluation_metrics_df = (evaluation_metrics_df.drop(
            columns=["split_num"]).groupby("config_name").mean().dropna(
                how="all"))

        # Rearranges columns so that train and test error of a config are side by side
        plot_df = pd.DataFrame()
        for metric_name in metric_dict.keys():
            plot_df[f"train_{metric_name}"] = evaluation_metrics_df[
                f"train_{metric_name}"]
            plot_df[f"test_{metric_name}"] = evaluation_metrics_df[
                f"test_{metric_name}"]

        if title is None:
            title = "Average evaluation metric across rolling windows"
        data = []
        # Each row (index) is a config. Adds each row to the bar plot.
        for index in plot_df.index:
            data.append(
                go.Bar(name=index,
                       x=plot_df.columns,
                       y=plot_df.loc[index].values))
        layout = go.Layout(
            xaxis=dict(title=xlabel),
            yaxis=dict(title=ylabel),
            title=title,
            showlegend=showlegend,
            barmode="group",
        )
        fig = go.Figure(data=data, layout=layout)

        return fig
Exemplo n.º 18
0
def bar_mul(player_name1: str, player_name2: str, metric1: str, metric2=None):
    '''Presents either a singular or grouped bar graph for a pair of players.
    
    Parameters
    ----------
    player_name1: string
        The name of the first player being searched for.
    
    player_name2: string
        The name of the second player being searched for.
    
    metric1: string
        The first metric to be visualized.
        
    metric2 (optional): string
        The second metric to be visualized.
    
    Returns
    -------
    None
    '''

    f_name1 = player_name1.split()[0]
    s_name1 = player_name1.replace(f_name1 + " ", "")

    f_name2 = player_name2.split()[0]
    s_name2 = player_name2.replace(f_name2 + " ", "")
    if metric2:
        players = [labels_dict[metric1], labels_dict[metric2]]

        fig = go.Figure(data=[
            go.Bar(name=player_name1,
                   x=players,
                   y=[
                       new_sample_data.query(
                           "first_name==@f_name1 and second_name==@s_name1")
                       [metric1].sum(),
                       new_sample_data.query(
                           "first_name==@f_name1 and second_name==@s_name1")
                       [metric2].sum()
                   ]),
            go.Bar(name=player_name2,
                   x=players,
                   y=[
                       new_sample_data.query(
                           "first_name==@f_name2 and second_name==@s_name2")
                       [metric1].sum(),
                       new_sample_data.query(
                           "first_name==@f_name2 and second_name==@s_name2")
                       [metric2].sum()
                   ])
        ])

        fig.update_layout(barmode='group')
    else:
        fig = px.bar(
            x=[player_name1, player_name2],
            y=[
                new_sample_data.query(
                    "first_name==@f_name1 and second_name==@s_name1")
                [metric1].sum(),
                new_sample_data.query(
                    "first_name==@f_name2 and second_name==@s_name2")
                [metric1].sum()
            ],
            labels={
                'x': labels_dict[metric1],
                'y': 'Value'
            },
            title=f'{player_name1} vs {player_name2}: {labels_dict[metric1]}')
    fig.show()
trace = go.Pie(labels=lab,
               values=val,
               marker=dict(colors=['royalblue', 'lime'],
                           line=dict(color='white', width=1.3)),
               rotation=90,
               hoverinfo="label+value+text")
layout = go.Layout(
    dict(
        title="Accidents by Month",
        plot_bgcolor="rgb(243,243,243)",
        paper_bgcolor="rgb(243,243,243)",
    ))

data = [trace]
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename="Basic Pie Chart")

target_col = ["Month"]
cat_cols_jan = df_dec.nunique()[df_dec.nunique() < 6].keys().tolist()
cat_cols_jan = [x for x in cat_cols_jan if x not in target_col]
num_cols_jan = [
    x for x in df_dec.columns if x not in cat_cols_jan + ID_col + target_col
]


def plot_pie(column):
    trace = go.Pie(
        values=df_dec[column].value_counts().values.tolist(),
        labels=df_dec[column].value_counts().keys().tolist(),
        #hoeverinfo="label+percent+name",
Exemplo n.º 20
0
def run_and_plot(test_cases):
    merge_times = []
    selection_times = []
    times = []
    initial_inversions = []
    merge_inversions_ratios = []
    select_inversions_ratios = []
    diff_inversions = []
    for i in test_cases:
        B = []
        mergearray = []
        selectarray = []

        for j in range(0, i):
            B.append(random.randint(0, 1000))
        [numinversions, trash] = inversions.count_inversions(B)
        initial_inversions.append(numinversions)
        [x, y, mergearray, selectarray] = runtime.test_runtime(B)
        merge_inversions_ratios.append(
            inversions.count_inversions(mergearray)[0] / numinversions)
        select_inversions_ratios.append(
            float(inversions.count_inversions(selectarray)[0]) / numinversions)
        diff_inversions.append(numinversions - select_inversions_ratios[-1])
        merge_times.append(x)
        selection_times.append(y)
        times.append(i)
    layout = go.Layout(
        title='Selection Sort Versus Merge Sort',
        xaxis=dict(title='size of array',
                   titlefont=dict(family='Courier New, monospace',
                                  size=18,
                                  color='#7f7f7f')),
        yaxis=dict(title='time in seconds',
                   titlefont=dict(family='Courier New, monospace',
                                  size=18,
                                  color='#7f7f7f')))
    trace0 = go.Scatter(x=times, y=merge_times, mode='markers', name='merge')
    trace1 = go.Scatter(x=times,
                        y=selection_times,
                        mode='markers',
                        name='selection')
    trace2 = go.Scatter(x=select_inversions_ratios,
                        y=selection_times,
                        mode='markers',
                        name='inversions ratio versus run time')
    trace3 = go.Scatter(x=initial_inversions,
                        y=selection_times,
                        mode='markers',
                        name='inversions number versus run time')
    trace4 = go.Scatter(x=initial_inversions,
                        y=select_inversions_ratios,
                        mode='markers',
                        name='inversions number versus run time')
    trace5 = go.Scatter(x=diff_inversions,
                        y=selection_times,
                        mode='markers',
                        name='differences')
    py.offline.plot([trace5], filename='differences.html')
    data = [trace0, trace1]
    fig = go.Figure(data=data, layout=layout)
    py.offline.plot(fig, filename='selectionvsmerge.html')
    layout = go.Layout(
        title='Inversions Ratios versus time for Selection Sort',
        xaxis=dict(title='Inversions Ratio',
                   titlefont=dict(family='Courier New, monospace',
                                  size=18,
                                  color='#7f7f7f')),
        yaxis=dict(title='time in seconds',
                   titlefont=dict(family='Courier New, monospace',
                                  size=18,
                                  color='#7f7f7f')))
    fig = go.Figure(data=[trace2], layout=layout)
    py.offline.plot(fig, filename='inversionsratios.html')
    layout = go.Layout(
        title='Initial Inversions number versus the time for Selection Sort',
        xaxis=dict(title='Number of initial Inversions in Array',
                   titlefont=dict(family='Courier New, monospace',
                                  size=18,
                                  color='#7f7f7f')),
        yaxis=dict(title='time in seconds',
                   titlefont=dict(family='Courier New, monospace',
                                  size=18,
                                  color='#7f7f7f')))
    fig = go.Figure(data=[trace3], layout=layout)
    py.offline.plot(fig, filename='inversions.html')
    layout = go.Layout(
        title=
        'Number of inversions versus the inversion ratio for Selection Sort',
        xaxis=dict(title='Number of initial inversions',
                   titlefont=dict(family='Courier New, monospace',
                                  size=18,
                                  color='#7f7f7f')),
        yaxis=dict(title='inversions ratio',
                   titlefont=dict(family='Courier New, monospace',
                                  size=18,
                                  color='#7f7f7f')))
    fig = go.Figure(data=[trace4], layout=layout)
    py.offline.plot(fig, filename='numvratio')
Exemplo n.º 21
0
plt.suptitle('Appearances comparison vs DC and Marvel', fontsize=20)
plt.show()

trace1 = go.Histogram(x=dc['ID'],
                      name='DC',
                      opacity=0.75,
                      marker=dict(color='rgb(52, 85, 159, 0.6)'))
trace2 = go.Histogram(x=marvel['ID'],
                      name='Marvel',
                      opacity=0.75,
                      marker=dict(color='rgb(84, 52, 15, 0.6)'))
data = [trace1, trace2]

layout = go.Layout(barmode='group', title='Comparison of Identities')

fig = go.Figure(data=data, layout=layout)
py.iplot(fig)

# create trace 1 that is 3d scatter

trace1 = go.Scatter3d(
    x=dc['APPEARANCES'],
    y=dc['YEAR'],
    z=dc['ALIVE'],
    name='DC',
    mode='markers',
    marker=dict(
        size=10,
        color=
        'rgb(58,56,72)',  # set color to an array/list of desired values      
    ))
def gen_map(library, patron_df):
    '''
    function produces plotly choropleth map based on query results from the runquery function
    
    Pandas is used to merge the queryresults data frame with the tigerline shape file and estimated population table from the Census Bureau
    Completed map is exported as a .html file
    '''

    zipfile = "zip://tl_2019_25_bg.zip"
    df = gpd.read_file(zipfile).to_crs("EPSG:4326")
    df.columns = df.columns.str.lower()

    #newdf = df.merge(patron_df, on='geoid', how='inner')
    df = df.merge(patron_df, on='geoid', how='inner')

    pop_df = pd.read_csv(
        "/Patron Maps/Data Sources/2019 acs pop estimate bg.csv",
        dtype={'geoid': str})

    df = df.merge(pop_df, on='geoid', how='inner')

    df['pct_cardholders'] = df.total_patrons / df.estimated_population * 100.00
    df['pct_cardholders'] = df['pct_cardholders'].round(decimals=2)

    zipjson = json.loads(df.to_json())

    #create list of fields that will be selectable in the map's drop down menu
    cols_dd = [
        'total_patrons', 'estimated_population', 'pct_cardholders',
        'total_checkouts', 'checkouts_per_patron', 'total_new_patrons',
        'total_active_patrons', 'pct_active', 'total_blocked_patrons',
        'pct_blocked'
    ]

    visible = np.array(cols_dd)

    traces = []
    buttons = []

    #Create map for each field included in the cols_dd list
    '''
    z field will determine the value used for shading each region of the map.
    Full list of colorscale options available here https://plotly.com/python/builtin-colorscales/
    hovertemplate used to change the fields and labels from the dataframe that will display in the hover tooltip box over each region of the map
    '''
    for value in cols_dd:
        traces.append(
            go.Choropleth(locations=df.index,
                          geojson=zipjson,
                          z=df[value],
                          colorbar_title=value,
                          colorscale='YlGnBu',
                          hovertemplate="<b>" + df.geographic_area_name +
                          "</b><br>" + "Total: " + df[value].astype(str) +
                          "<extra></extra>",
                          visible=True if value == cols_dd[0] else False))

        buttons.append(
            dict(label=value,
                 method='update',
                 args=[{
                     'visible': list(visible == value)
                 }, {
                     'title': f'<b>{value}</b>'
                 }]))

    updatemenus = [{'active': 0, 'buttons': buttons}]

    fig = go.Figure(data=traces, layout=dict(updatemenus=updatemenus))

    first_title = cols_dd[0]
    fig.update_layout(title=f'<b>{first_title}</b>',
                      title_x=0.5,
                      geo=dict(scope='usa'))

    fig.update_geos(fitbounds="locations", visible=True)

    #Write resulting map to html file
    pio.write_html(fig,
                   file=library + 'AllInOneMap{}.html'.format(date.today()),
                   auto_open=False)
Exemplo n.º 23
0
def prepareScatter(model,
                   projection,
                   sample_info,
                   labelby,
                   outprefix,
                   components=components):
    """
    Prepares a plotly instance for figure output. A scatterplot will be created
    based on the PCA coordinates and coloring will be based on labels provided
    by the sample file. ONLY THE FIRST TWO COMPONENTS ARE PLOTED
    Taken from:
        https://plot.ly/ipython-notebooks/principal-component-analysis/
        with minor modifications to adapt for a specific format
    """
    # Get vector of explained variance
    explained_variance = model.explained_variance_ratio_
    print(explained_variance[0:10])

    traces = []
    labels = np.array([i[labelby] for i in sample_info])
    sampleNames = np.array([i[0] for i in sample_info])

    xp = projection[:, components[0]]
    yp = projection[:, components[1]]
    # For Site
    colors = cl.scales['11']['div']['RdBu']

    # loop over labels
    unique_labels = list(sorted(set(labels)))
    print(len(unique_labels),"unique labels.")

    for i in range(len(unique_labels)):
        label = unique_labels[i]
        print(label, colors[i])
        if label == 'NA':
            showlegend = False
        else:
            showlegend = False
        # Create traces
        x1 = projection[labels == label, components[0]]
        y1 = projection[labels == label, components[1]]
        trace = go.Scattergl(x=x1,#*scalex,
                             y=y1,#*scaley,
                             mode='markers',
                             text=sampleNames[labels == label],
                             name=label[0:6],
                             marker=dict(size=35,
                                         symbol='circle',
                                         line=dict(color=colors[i],
                                                     width=0.5),
                                         color=colors[i],
                                         opacity=1))
        traces.append(trace)
    data = traces

    layout = go.Layout(title="",
                       font=dict(size=35,),
                       paper_bgcolor='rgba(0,0,0,0)',
                       plot_bgcolor='rgba(0,0,0,0)',
                       titlefont=dict(size=50,
                                      family='arial'),
                       margin=dict(b=70,
                                   t=0,
                                   l=90,
                                   r=10),
                       xaxis=dict(title="",
                                  showline=True,
                                  visible=True,
                                  zeroline=True,
                                  tickfont=dict(size=50)),

                       yaxis=dict(title="",
                                  showline=True,
                                  zeroline=True,
                                  tickfont=dict(size=50)),

                       #shapes=loading_vecs,
                       legend=dict(x=0,
                                   y=-.2,
                                   orientation="h",
                                   bgcolor='#E2E2E2'))
    fig = go.Figure(data=data, layout=layout)
    return fig
Exemplo n.º 24
0
        num_values[num_keys.index(fig_kwargs['z_key'])][0],
        num_values[num_keys.index(fig_kwargs['z_key'])][1]
    ]

    if keys_dict[fig_kwargs['c_key']].\
            get('type', KEY_TYPES['NUM']) == KEY_TYPES['NUM']:
        fig_kwargs['c_range'] = [
            num_values[num_keys.index(fig_kwargs['c_key'])][0],
            num_values[num_keys.index(fig_kwargs['c_key'])][1]
        ]
    else:
        fig_kwargs['c_range'] = [0, 0]

    fig_kwargs['c_type'] = keys_dict[fig_kwargs['c_key']].get(
        'type', KEY_TYPES['NUM'])
    fig_kwargs['ref_name'] = 'Host Vehicle'
    fig_kwargs['hover'] = keys_dict

    fig_kwargs['title'] = file['name'][0:-4]

    fig_kwargs['height'] = 750

    fig = go.Figure(
        get_animation_data(filtered_table, img_list=img_list, **fig_kwargs))

    now = datetime.datetime.now()
    timestamp = now.strftime('%Y%m%d_%H%M%S')

    fig.write_html('data/' + case + '/images/' + timestamp + '_' +
                   file['name'][0:-4] + '_3dview.html')
Exemplo n.º 25
0
import streamlit as st
import pandas as pd
import numpy as np
import requests
from plotly.offline import iplot
import plotly.graph_objs as go
import plotly.express as px
from pandas.io.json import json_normalize
from streamlit.ScriptRunner import StopException, RerunException

fig = go.Figure()
hide_streamlit_style = """
        <title> Half Explot </title>
        <style>
        footer {visibility: hidden;}
        .sidebar .sidebar-content {background-image: linear-gradient(180deg,#5cbede,#e0debf00);}
        .st-b9 {background-color: rgb(47 38 47 / 76%);}
        .st-b4 {color: rgb(111 235 255);}
        .btn-outline-secondary {
        border-color: #09ab3b85;
        color: #f9f9f9;
        }
        </style>
        """
st.markdown(hide_streamlit_style, unsafe_allow_html=True) 

st.write("""
# COVID 19 Live Dataset 🚨
[Coronavirus COVID19 API](https://documenter.getpostman.com/view/10808728/SzS8rjbc?version=latest#81447902-b68a-4e79-9df9-1b371905e9fa) is used to get the data in this app.
""")
Exemplo n.º 26
0
def update_graph(value, slider_value, selectedData, prevLayout, mapControls):
    zoom = 12.0
    latInitial = 40.7272
    lonInitial = -73.991251
    bearing = 0

    listStr = get_lat_lon_color(selectedData, value, slider_value)

    if (prevLayout is not None and mapControls is not None
            and 'lock' in mapControls):
        zoom = float(prevLayout['mapbox']['zoom'])
        latInitial = float(prevLayout['mapbox']['center']['lat'])
        lonInitial = float(prevLayout['mapbox']['center']['lon'])
        bearing = float(prevLayout['mapbox']['bearing'])
    return go.Figure(
        data=Data([
            Scattermapbox(
                lat=eval(listStr)['Lat'],
                lon=eval(listStr)['Lon'],
                mode='markers',
                hoverinfo="lat+lon+text",
                text=eval(listStr).index.hour,
                marker=Marker(
                    color=np.append(np.insert(eval(listStr).index.hour, 0, 0),
                                    23),
                    colorscale=[[0, "#F4EC15"], [0.04167, "#DAF017"],
                                [0.0833, "#BBEC19"], [0.125, "9DE81B"],
                                [0.1667, "#80E41D"], [0.2083, "#66E01F"],
                                [0.25, "#4CDC20"], [0.292, "#34D822"],
                                [0.333, "#24D249"], [0.375, "#25D042"],
                                [0.4167, "#26CC58"], [0.4583, "#28C86D"],
                                [0.50, "#29C481"], [0.54167, "#2AC093"],
                                [0.5833, "#2BBCA4"], [1.0, "#613099"]],
                    opacity=0.5,
                    size=5,
                    colorbar=dict(thicknessmode="fraction",
                                  title="Time of<br>Day",
                                  x=0.935,
                                  xpad=0,
                                  nticks=24,
                                  tickfont=dict(color='white'),
                                  titlefont=dict(color='white'),
                                  titleside='left')),
            ),
            Scattermapbox(
                lat=[
                    "40.7505", "40.8296", "40.7484", "40.7069", "40.7527",
                    "40.7127", "40.7589", "40.8075", "40.7489"
                ],
                lon=[
                    "-73.9934", "-73.9262", "-73.9857", "-74.0113", "-73.9772",
                    "-74.0134", "-73.9851", "-73.9626", "-73.9680"
                ],
                mode='markers',
                hoverinfo="text",
                text=[
                    "Madison Square Garden", "Yankee Stadium",
                    "Empire State Building", "New York Stock Exchange",
                    "Grand Central Station", "One World Trade Center",
                    "Times Square", "Columbia University", "United Nations HQ"
                ],
                # opacity=0.5,
                marker=Marker(size=6, color="#ffa0a0"),
            ),
        ]),
        layout=Layout(
            autosize=True,
            height=750,
            margin=Margin(l=0, r=0, t=0, b=0),
            showlegend=False,
            mapbox=dict(
                accesstoken=mapbox_access_token,
                center=dict(
                    lat=latInitial,  # 40.7272
                    lon=lonInitial  # -73.991251
                ),
                style='dark',
                bearing=bearing,
                zoom=zoom),
            updatemenus=[
                dict(buttons=([
                    dict(args=[{
                        'mapbox.zoom': 12,
                        'mapbox.center.lon': '-73.991251',
                        'mapbox.center.lat': '40.7272',
                        'mapbox.bearing': 0,
                        'mapbox.style': 'dark'
                    }],
                         label='Reset Zoom',
                         method='relayout')
                ]),
                     direction='left',
                     pad={
                         'r': 0,
                         't': 0,
                         'b': 0,
                         'l': 0
                     },
                     showactive=False,
                     type='buttons',
                     x=0.45,
                     xanchor='left',
                     yanchor='bottom',
                     bgcolor='#323130',
                     borderwidth=1,
                     bordercolor="#6d6d6d",
                     font=dict(color="#FFFFFF"),
                     y=0.02),
                dict(buttons=([
                    dict(args=[{
                        'mapbox.zoom': 15,
                        'mapbox.center.lon': '-73.9934',
                        'mapbox.center.lat': '40.7505',
                        'mapbox.bearing': 0,
                        'mapbox.style': 'dark'
                    }],
                         label='Madison Square Garden',
                         method='relayout'),
                    dict(args=[{
                        'mapbox.zoom': 15,
                        'mapbox.center.lon': '-73.9262',
                        'mapbox.center.lat': '40.8296',
                        'mapbox.bearing': 0,
                        'mapbox.style': 'dark'
                    }],
                         label='Yankee Stadium',
                         method='relayout'),
                    dict(args=[{
                        'mapbox.zoom': 15,
                        'mapbox.center.lon': '-73.9857',
                        'mapbox.center.lat': '40.7484',
                        'mapbox.bearing': 0,
                        'mapbox.style': 'dark'
                    }],
                         label='Empire State Building',
                         method='relayout'),
                    dict(args=[{
                        'mapbox.zoom': 15,
                        'mapbox.center.lon': '-74.0113',
                        'mapbox.center.lat': '40.7069',
                        'mapbox.bearing': 0,
                        'mapbox.style': 'dark'
                    }],
                         label='New York Stock Exchange',
                         method='relayout'),
                    dict(args=[{
                        'mapbox.zoom': 15,
                        'mapbox.center.lon': '-73.785607',
                        'mapbox.center.lat': '40.644987',
                        'mapbox.bearing': 0,
                        'mapbox.style': 'dark'
                    }],
                         label='JFK Airport',
                         method='relayout'),
                    dict(args=[{
                        'mapbox.zoom': 15,
                        'mapbox.center.lon': '-73.9772',
                        'mapbox.center.lat': '40.7527',
                        'mapbox.bearing': 0,
                        'mapbox.style': 'dark'
                    }],
                         label='Grand Central Station',
                         method='relayout'),
                    dict(args=[{
                        'mapbox.zoom': 15,
                        'mapbox.center.lon': '-73.9851',
                        'mapbox.center.lat': '40.7589',
                        'mapbox.bearing': 0,
                        'mapbox.style': 'dark'
                    }],
                         label='Times Square',
                         method='relayout')
                ]),
                     direction="down",
                     pad={
                         'r': 0,
                         't': 0,
                         'b': 0,
                         'l': 0
                     },
                     showactive=False,
                     bgcolor="rgb(50, 49, 48, 0)",
                     type='buttons',
                     yanchor='bottom',
                     xanchor='left',
                     font=dict(color="#FFFFFF"),
                     x=0,
                     y=0.05)
            ]))
Exemplo n.º 27
0
                         placeholder='Narrow down location')
        ],
        style={'display': 'none'},
        id='location-5-div',
    ),
    html.Br(),
    #html.Button(id='submit', n_clicks=0, children='Make Pyramid!',color='primary')
    dbc.Button('Make Pyramid',
               color='primary',
               id='submit',
               type='submit',
               n_clicks=0)
])

# placeholder Triangle Figure"
fig = go.Figure(go.Scatter(x=[0, 1, 2, 0], y=[0, 2, 0, 0], fill="toself"))
fig.update_layout(title_text="No Info Yet")

column2 = dbc.Col([
    #html.Img(src=app.get_asset_url('placeholder.png'))
    dcc.Graph(id='pyramid', figure=fig)
])
layout = dbc.Row([column1, column2])


@app.callback(
    Output('pyramid', 'figure'),
    [
        Input('submit', 'n_clicks'),  # I think button click is fixed
        State('ticks-url', 'value'),
        State('style', 'value'),
Exemplo n.º 28
0
def update_histogram(datePicked, selection):
    date_picked = dt.strptime(datePicked, "%Y-%m-%d")
    monthPicked = date_picked.month - 4
    dayPicked = date_picked.day - 1

    [xVal, yVal, colorVal] = get_selection(monthPicked, dayPicked, selection)

    layout = go.Layout(
        bargap=0.01,
        bargroupgap=0,
        barmode="group",
        margin=go.layout.Margin(l=10, r=0, t=0, b=50),
        showlegend=False,
        plot_bgcolor="#323130",
        paper_bgcolor="#323130",
        dragmode="select",
        font=dict(color="white"),
        xaxis=dict(
            range=[-0.5, 23.5],
            showgrid=False,
            nticks=25,
            fixedrange=True,
            ticksuffix=":00",
        ),
        yaxis=dict(
            range=[0, max(yVal) + max(yVal) / 4],
            showticklabels=False,
            showgrid=False,
            fixedrange=True,
            rangemode="nonnegative",
            zeroline=False,
        ),
        annotations=[
            dict(
                x=xi,
                y=yi,
                text=str(yi),
                xanchor="center",
                yanchor="bottom",
                showarrow=False,
                font=dict(color="white"),
            ) for xi, yi in zip(xVal, yVal)
        ],
    )

    return go.Figure(
        data=[
            go.Bar(x=xVal, y=yVal, marker=dict(color=colorVal), hoverinfo="x"),
            go.Scatter(
                opacity=0,
                x=xVal,
                y=yVal / 2,
                hoverinfo="none",
                mode="markers",
                marker=dict(color="rgb(66, 134, 244, 0)",
                            symbol="square",
                            size=40),
                visible=True,
            ),
        ],
        layout=layout,
    )
Exemplo n.º 29
0
            text_by_word = [text[i]]
    word_data_groups.append((features_by_word, labels_by_word, text_by_word))

    # MAP DOWN DATA. (Make Function?)
    reducer = umap.UMAP(n_neighbors=80, min_dist=0, init='random', n_epochs=30)
    embeddings = [reducer.fit_transform(group[0]) for group in word_data_groups]
    # if len(word_data_groups) > 1 : # If there is more than one word, prep a graph with all words together
    #     embeddings.append(reducer.fit_transform([group[0] for group in word_data_groups])) 
    clusters_by_embedding = [hdbscan.HDBSCAN().fit_predict(embedding) for embedding in embeddings]
    clustered_by_embedding = [(cluster >= 0) for cluster in clusters_by_embedding] # a list of a lists, each marking whether a case was clustered in paired embedding 
    
    for (i, embedding) in tqdm(enumerate(embeddings)):
        clustered = clustered_by_embedding[i] # The array defining whether they were grouped (could just set to all yes if user tags doesn't care?)
        title = word_data_groups[i][1][0] #a label from the current group
        fig = go.Figure(
            layout = {"title" : {"text": title}},
            data=go.Scatter(
                x=embedding[clustered, 0],
                y=embedding[clustered, 1],
                hovertext=(np.array(word_data_groups[i][2]))[clustered],
                mode='markers',
                marker=dict(
                    color=clusters_by_embedding[i][clustered],
                    line=dict(
                        width=1,
                        color='DarkSlateGrey'
                    ),
                )
            )
        )
        plot(fig, filename=f"./graphs/{title}.html")
def Population(fileNum, atomLocations, showLoadingRate=True, showLoadingPic=False, plotCounts=False, countsMain=False,
            indvHist=True, histMain=False, simplePlot=False, showTotalHist=False, histBins=100, picsPerRep=1, whichPic=0, **StandardArgs):
    """
    Standard data analysis package for looking at loading rates throughout an experiment.
    return key, loadingRateList, loadingRateErr

    See standardLoadingAnalysis for valid standardArgs

    This routine is designed for analyzing experiments with only one picture per cycle. Typically
    These are loading exeriments, for example. There's no survival calculation.

    :param fileNum:
    :param atomLocations:
    :param showIndividualHist:
    :param showLoadingRate:
    :param showLoadingPic:
    :param StandardArgs:
    :param countsMain:
    :param plotCounts:
    :return:
    """

    res = standardPopulationAnalysis(fileNum, atomLocations, whichPic, picsPerRep, **StandardArgs)
    (pic1Data, thresholds, avgPic, key, loadingRateErr, loadingRateList, allLoadingRate, allLoadingErr, loadFits,
            fitModules, keyName, totalPic1AtomData, rawData, atomLocations, avgFits, atomImages, totalAvg, totalErr) = res 
    maxHeight = np.max(arr([np.histogram(data.flatten(), bins=histBins)[0] for data in pic1Data]).flatten())

    totalHist = []
    if showTotalHist:
        d, _ = np.histogram(pic1Data.flatten(), bins=100)
        totalHist.append(go.Histogram(x=pic1Data.flatten(), nbinsx=100, legendgroup='avg',
                                      showlegend=False, xbins=dict(start=min(pic1Data.flatten()),
                                                                   end=max(pic1Data.flatten())),
                                      marker=dict(color='#000000')))
        totalHist.append(go.Scatter(x=[np.mean(thresholds), np.mean(thresholds)], y=[0, max(d)],
                                    showlegend=False, mode='lines', line={'color': '#000000', 'width': 1},
                                    hoverinfo='none', legendgroup='avg'))
    colors, _ = getColors(len(atomLocations) + 1)
    countsFig = []
    if plotCounts:
        for atom, color in zip(atomLocations, colors):
            countsFig.append(go.Scatter(x=list(range(pic1Data[atom].flatten().size)), y=pic1Data[atom].flatten(),
                                        showlegend=False, mode='markers', line={'color': '#000000', 'width': 1},
                                        hoverinfo='none', legendgroup=str(atom), marker={'color': color, 'size':1}))
    indvHistFig = []
    alphaVal = 0.5
    if indvHist:
        for i, (atom, color, threshold) in enumerate(zip(atomLocations, colors, thresholds)):
            indvHistFig.append(go.Histogram(x=pic1Data[i].flatten(), legendgroup=str(atom), name=str(atom),
                                            nbinsx=histBins, showlegend=simplePlot, marker=dict(color=color),
                                            opacity=alphaVal))
            indvHistFig.append(go.Scatter(y=[0, maxHeight], x=[threshold, threshold], showlegend=False,
                                          mode='lines', line={'color': color, 'width': 1}, hoverinfo='none',
                                          legendgroup=str(atom)))
    if showLoadingPic:
        loadingPic = np.zeros(avgPic.shape)
        locFromKey = []
        minHor = min(transpose(key)[0])
        minVert = min(transpose(key)[1])
        for keyItem in key:
            locFromKey.append([int((keyItem[0] - minHor) / 9 * 2 + 2), int((keyItem[1] - minVert) / 9 * 2 + 2)])
        for i, loc in enumerate(locFromKey):
            loadingPic[loc[1]][loc[0]] = max(loadingRateList[i])
    if showLoadingRate:
        avgFig, mainPlot = [[] for _ in range(2)]
        avgFig.append(go.Heatmap(z=avgPic, colorscale='Viridis', colorbar=go.heatmap.ColorBar(x=1, y=0.15, len=0.3)))
        for err, loc, color, load, fitData in zip(loadingRateErr, atomLocations, colors, loadingRateList, loadFits):
            mainPlot.append(go.Scatter(x=key, y=load, error_y={'type': 'data', 'array': err, 'color': color},
                                       mode='markers', name=str(loc), legendgroup=str(loc),
                                       marker={'color': color}, opacity=alphaVal))
            avgFig.append(go.Scatter(x=[loc[1]], y=[loc[0]], mode='markers', hoverinfo='none',
                              showlegend=False, legendgroup=str(loc), marker={'size': 2, 'color': '#FF0000'}))
            if fitModules is not None:
                print(loc, errString(fitData['vals'][1], fitData['errs'][1], 4))
                mainPlot.append(go.Scatter(x=fitData['x'], y=fitData['nom'], line={'color': color},
                                           legendgroup=str(loc), showlegend=False, opacity=alphaVal))
                if fitData['std'] is not None:
                    mainPlot.append(go.Scatter(x=fitData['x'], y=fitData['nom'] + fitData['std'],
                                               opacity=alphaVal / 2, line={'color': color},
                                               legendgroup=str(loc), showlegend=False, hoverinfo='none'))
                    mainPlot.append(go.Scatter(x=fitData['x'], y=fitData['nom'] - fitData['std'],
                                               opacity=alphaVal / 2, line={'color': color},
                                               legendgroup=str(loc), fill='tonexty', showlegend=False,
                                               hoverinfo='none'))
        mainPlot.append(go.Scatter(x=key, y=allLoadingRate, marker={'color': '#000000'},
                                   error_y={'type': 'data', 'array': allLoadingErr, 'color': "#000000"},
                                   mode='markers', name='avg', legendgroup='avg'))
        if fitModules is not None:
            print('avg fit:', errString(avgFits['vals'][1], avgFits['errs'][1], 4))
            mainPlot.append(go.Scatter(x=avgFits['x'], y=avgFits['nom'], line={'color': '#000000'},
                                       legendgroup='avg', showlegend=False, opacity=alphaVal))
            if avgFits['std'] is not None:
                mainPlot.append(go.Scatter(x=avgFits['x'], y=avgFits['nom'] + avgFits['std'],
                                           opacity=alphaVal / 2, line={'color': '#000000'},
                                           legendgroup='avg', showlegend=False, hoverinfo='none'))
                mainPlot.append(go.Scatter(x=avgFits['x'], y=avgFits['nom'] - avgFits['std'],
                                           opacity=alphaVal / 2, line={'color': '#000000'},
                                           legendgroup='avg', fill='tonexty', showlegend=False,
                                           hoverinfo='none'))
        if simplePlot:
            if countsMain:
                plotData = countsFig
                layout = go.Layout(xaxis={'title': 'Pic #'}, yaxis={'title': 'Count #'})
            elif histMain:
                if showTotalHist:
                    histToShow = totalHist
                elif indvHist:
                    histToShow = indvHistFig
                else:
                    histToShow = []
                plotData = histToShow
                layout = go.Layout(xaxis={'title': 'Pic #'}, yaxis={'title': 'Count #'}, barmode='overlay')
            else:
                plotData = mainPlot
                layout = go.Layout(xaxis={'title': keyName}, yaxis={'title': 'Loading %', 'range': [0,1]})
            fig = go.Figure(data=plotData, layout=layout)
        else:
            fig = make_subplots(
                rows=3, cols=12, print_grid=False, horizontal_spacing=0, vertical_spacing=0.05,
                specs=[[{'rowspan': 3, 'colspan': 9}, None, None, None, None, None, None, None, None, {'colspan': 2},
                        None, {}],
                       [None, None, None, None, None, None, None, None, None, {'colspan': 3}, None, None],
                       [None, None, None, None, None, None, None, None, None, {'colspan': 3}, None, None]])
            if countsMain:
                mainLoc = (1, 10)
                mainNum = '2'
                countsNum = '1'
                countsLoc = (1, 1)
            else:
                mainLoc = (1, 1)
                mainNum = '1'
                countsNum = '2'
                countsLoc = (1, 10)
            for mainLine in mainPlot:
                fig.add_trace(mainLine, mainLoc[0], mainLoc[1])
            for avgPart in avgFig:
                fig.add_trace(avgPart, 3, 10)
            for counts in countsFig:
                fig.add_trace(counts, countsLoc[0], countsLoc[1])
            if showTotalHist:
                histToShow = totalHist
            elif indvHist:
                histToShow = indvHistFig
            else:
                histToShow = []
            for hist in histToShow:
                fig.add_trace(hist, 2, 10)
            layout = go.Layout(plot_bgcolor="rgb(182, 215, 168)", paper_bgcolor="rgb(182, 215, 168)")
            fig['layout'] = layout
            fig['layout'].update(barmode='overlay', plot_bgcolor="rgb(182, 215, 168)", paper_bgcolor="rgb(182, 215, 168)")
            fig['layout']['yaxis' + mainNum].update(title="Loading %", range=[0, 1])
            fig['layout']['xaxis' + mainNum].update(title=str(keyName))
            fig['layout']['yaxis' + countsNum].update(title="Count", range=[min(pic1Data.flatten()), max(pic1Data.flatten())])
            fig['layout']['xaxis' + countsNum].update(range=[0, len(pic1Data[0].flatten())])
            fig['layout']['yaxis3'].update(range=[min(pic1Data.flatten()), max(pic1Data.flatten())], showticklabels=False)
            fig['layout']['xaxis3'].update(showticklabels=False)
            # fig['layout']['yaxis4'].update(title="Loading %", range=[0,1])
            # fig['layout']['yaxis5'].update(title="Average Image")
        print('plotting figure...')
        iplot(fig)
    return key, loadingRateList, loadingRateErr, totalPic1AtomData, rawData, allLoadingRate