当前位置: 首页>>代码示例>>Python>>正文


Python FigureFactory.create_distplot方法代码示例

本文整理汇总了Python中plotly.tools.FigureFactory.create_distplot方法的典型用法代码示例。如果您正苦于以下问题:Python FigureFactory.create_distplot方法的具体用法?Python FigureFactory.create_distplot怎么用?Python FigureFactory.create_distplot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plotly.tools.FigureFactory的用法示例。


在下文中一共展示了FigureFactory.create_distplot方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dist_plot

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
def dist_plot(df, 
              groupby=None,
              val=None,
              bin_size=1, 
              title=None,
              show_hist=True,
              show_kde=True, 
              show_rug=True, 
              show_legend=True, 
              figsize=None,
              outfile=None,
              xlabel=None,
              ylabel=None):
    
    if groupby is None:
        fig = FF.create_distplot([df[c] for c in df.columns], 
                                     df.columns.values.tolist(), 
                                     bin_size=bin_size,
                                     show_rug=show_rug,
                                     show_curve=show_kde)
    else:
        groups = sorted(df[groupby].unique().tolist(), reverse=True)
        data = []
        if val is None:
            val = df.columns.drop(groupby)[0]  # choose first non-groupby column
            
        for group in groups:
            mask = df[groupby] == group
            data.append(df.loc[mask, val])
            
        fig = FF.create_distplot(data, 
                                 groups, 
                                 bin_size=bin_size,
                                 show_hist=show_hist,
                                 show_rug=show_rug,
                                 show_curve=show_kde)
        
    fig['layout'].update(showlegend=show_legend)
    
    if title:
        fig['layout'].update(title=title)

    if xlabel:
        fig['layout'].update(xaxis=go.XAxis(title=xlabel))

    if ylabel:
        fig['layout'].update(yaxis=go.YAxis(title=ylabel))


        
    if figsize and len(figsize) == 2:
        fig['layout'].update(width=figsize[0])
        fig['layout'].update(height=figsize[1])
        
    ol.iplot(fig, show_link=False)
    
    # write figure to HTML file
    if outfile:
        print('Exporting copy of figure to %s...' % outfile)
        ol.plot(fig, auto_open=False, filename=outfile)
开发者ID:dustinstansbury,项目名称:quick_plotly,代码行数:62,代码来源:quick_plotly.py

示例2: plot_Age

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
def plot_Age(path, feature, type_):
    feature = pd.DataFrame(feature)
    feature = feature.reset_index()
    data = folder_reader(path)
    data.columns = ['temperature', 'wind', 'age', 'total']
    aux = data[data.age < 1950]
    aux = aux.groupby(type_)['total'].sum()
    aux = aux.reset_index()
    aux = pd.merge(aux, feature, how='left', left_index=type_, right_index="index")
    number = aux[aux.columns[1]] * 100 / aux[aux.columns[3]]
    Temp_1 = np.repeat(aux[aux.columns[0]].values, number.round(0).astype(int))

    aux = data[data.age >= 1950]
    aux = aux[aux.age < 1985]
    aux = aux.groupby(type_)['total'].sum()
    aux = aux.reset_index()
    aux = pd.merge(aux, feature, how='left', left_index=type_, right_index="index")
    number = aux[aux.columns[1]] * 100 / aux[aux.columns[3]]
    Temp_2 = np.repeat(aux[aux.columns[0]].values, number.round(0).astype(int))

    aux = data[data.age >= 1985]
    aux = aux.groupby(type_)['total'].sum()
    aux = aux.reset_index()
    aux = pd.merge(aux, feature, how='left', left_index="wind", right_index="index")
    number = aux[aux.columns[1]] * 100 / aux[aux.columns[3]]
    Temp_3 = np.repeat(aux[aux.columns[0]].values, number.round(0).astype(int))

    hist_data = [Temp_1, Temp_2, Temp_3]
    group_labels = ['Older than 65', 'Betwen 30-65', 'Younger than 30']
    colors = ['rgb(0, 0, 100)', 'rgb(0, 200, 200)', 'rgb(0, 300, 300)']
    fig = FF.create_distplot(hist_data, group_labels, colors=colors)
    plot_url = py.offline.plot(fig)
开发者ID:obr214,项目名称:BD_FinalProject,代码行数:34,代码来源:plot_functions.py

示例3: make_plotly_figs

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
def make_plotly_figs():
    from plotly.tools import FigureFactory as FF

    import numpy as np

    x1 = np.random.randn(200)

    hist_data = [x1]

    group_labels = ['Group 1']

    # Create distplot with curve_type set to 'normal'
    fig = FF.create_distplot(hist_data, group_labels, bin_size=.25, show_curve=False)

    # Add title
    fig['layout'].update(title='Plot')
    return [fig]
开发者ID:aretha-hep,项目名称:aretha-web,代码行数:19,代码来源:make_plots.py

示例4: distPlot

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
def distPlot(request):
    df = cPickle.loads(str(request.session['dataframe']))
    x0 = df[request.GET['x_axis']]
    x1 = df[request.GET['y_axis']]
    x2 = df[request.GET['z_axis']]

    data=[x0,x1,x2]
    labels = [request.GET['x_axis'],request.GET['y_axis'],request.GET['z_axis']]
    colors = ['rgb(0, 0, 100)', 'rgb(0, 200, 200)','rgb(0, 200, 100)']
    fig = FF.create_distplot(
        data, labels, bin_size=.2, colors=colors)
    fig['layout'].update(title='Distplot of {} vs {} vs {}'.format(request.GET['x_axis'], \
                                                                   request.GET['y_axis'], \
                                                                   request.GET['z_axis']))
    url = py.plot(fig, filename='Distplot with Normal Curve', auto_open=False)
    dashboard_json = {
        "rows": [
            [{"plot_url": url}]
        ],
        "banner": {
            "visible": False,
            "backgroundcolor": "#2A3F54",
            "textcolor": "white",
            # "title": "{} group_by {}".format(request.GET['x_axis'], request.GET['y_axis']),
            "links": []
        },
        "requireauth": False,
        "auth": {
            "username": "Acme Corp",
            "passphrase": ""
        }
    }
    response = requests.post('https://dashboards.ly/publish',
                             data={'dashboard': json.dumps(dashboard_json)},
                             headers={'content-type': 'application/x-www-form-urlencoded'})
    response.raise_for_status()
    dashboard_url = response.json()['url']
    return dashboard_url
开发者ID:hiteshpaul,项目名称:Salesforecasting,代码行数:40,代码来源:plot.py

示例5: _plot_accuracy_distribution

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
def _plot_accuracy_distribution(dsets_kpis):
    """
    Generate plotly histogram of accuracy distributions, overlaid
    Return a plot structure
    """

    data = []
    for key in dsets_kpis.keys():
        accuracy = dsets_kpis[key]['accuracy']
        data.append(accuracy)

    group_labels = dsets_kpis.keys()

    fig = FF.create_distplot(data, group_labels, show_hist=False)
    fig['layout']['xaxis'].update(title='Accuracy')
    fig['layout']['xaxis']['tickfont'].update(size=24)
    fig['layout']['xaxis']['titlefont'].update(size=24)
    fig['layout']['yaxis'].update(title='density')
    fig['layout']['yaxis']['tickfont'].update(size=24)
    fig['layout']['yaxis']['titlefont'].update(size=24)
    fig['layout']['font']['size'] = 20

    return fig
开发者ID:knyquist,项目名称:pbinternal2,代码行数:25,代码来源:accuracy_plots.py

示例6: plot_Gender

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
def plot_Gender(path, feature, type_):
    feature = pd.DataFrame(feature)
    feature = feature.reset_index()
    data = folder_reader(path)
    data.columns = ['temperature', 'wind', 'gender', 'total']
    aux = data[data.gender == 1]
    aux = aux.groupby(type_)['total'].sum()
    aux = aux.reset_index()
    aux = pd.merge(aux, feature, how='left', left_index=type_, right_index="index")
    number = aux[aux.columns[1]] * 100 / aux[aux.columns[3]]
    Temp_1 = np.repeat(aux[aux.columns[0]].values, number.round(0).astype(int))

    aux = data[data.gender == 2]
    aux = aux.groupby(type_)['total'].sum()
    aux = aux.reset_index()
    aux = pd.merge(aux, feature, how='left', left_index=type_, right_index="index")
    number = aux[aux.columns[1]] / aux[aux.columns[3]]
    Temp_2 = np.repeat(aux[aux.columns[0]].values, number.round(0).astype(int))

    hist_data = [Temp_1, Temp_2]
    group_labels = ['Man', 'Woman']
    colors = ['rgb(0, 0, 100)', 'rgb(0, 200, 200)']
    fig = FF.create_distplot(hist_data, group_labels, colors=colors)
    plot_url = py.offline.plot(fig)
开发者ID:obr214,项目名称:BD_FinalProject,代码行数:26,代码来源:plot_functions.py

示例7: Height

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
                     width =1
                     ),
               opacity=0.8
               )
    )
    
    dataList.append(name)

layout = go.Layout(scene = go.Scene(xaxis=dict(title='Heel Height (mm)'), yaxis=dict(title='Forefoot Height (mm)'),zaxis=dict(title ='Weight (oz)')),
                   margin=dict(l=0,r=0,b=0,t=0))

fig = go.Figure(data = dataList, layout=layout)
plot_url = py.plot(fig, filename="3d-scatter-test")

#%%
hist_data= []
for x in brands:
    data = rwDF[(rwDF.Brand==x)]['Price']
    data.dropna(inplace=True)
    hist_data.append(data)

fig = FF.create_distplot(hist_data, brands, bin_size=20)
plot_url=py.plot(fig, filename="Multiple Hists")

#%%
# Average Price, Forefoot Height, Heel Height, Weight by different Runningwarehouse shoe type
rwDF.groupby('Shoe Type').mean().T.plot(kind = 'bar')

sns.pairplot(rwDF,vars=['Forefoot Height (mm)', 'Heel Height (mm)', 'Weight (oz)', 'Drop (mm)'],  hue="Brand", palette="husl")

sns.pairplot(rwDF,vars=['Forefoot Height (mm)', 'Heel Height (mm)', 'Weight (oz)', 'Drop (mm)'],  hue="Shoe Type")
开发者ID:cwberardi,项目名称:RS-Sraper,代码行数:33,代码来源:RunningWarehouseScrape(wAttributes).py

示例8: dict

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
    from plotly.tools import FigureFactory as FF

    if args['-t']:
        import numpy as np
        dataMap = {'test': np.random.randn(400)}

    hist_data = []
    group_labels = []
    for k,v in dataMap.items():
        hist_data.append(v)
        group_labels.append(k)

    # Create distplot
    colors = ['#37AA9C', '#2BCDC1','#F66095','#393E46']
    fig = FF.create_distplot(hist_data, group_labels,bin_size=0.2,
    curve_type='normal',
    colors=colors,
    show_rug=False)

    afsize = 10 #annotation font size.
    astring= '13q12.13'
    layout = go.Layout(
        annotations=[
            dict(
                x=0.018476,
                y=0.085,
                xref='x',
                yref='y',
                #yref='paper',
                text='FSGS_' + astring,
                showarrow=True,
                arrowhead=2,
开发者ID:wavefancy,项目名称:BIDMC-PYTHON,代码行数:34,代码来源:DisPlotESRDChr13.py

示例9: dict

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
    import plotly
    import plotly.plotly as py
    import plotly.graph_objs as go
    from plotly.tools import FigureFactory as FF

    import numpy as np
    dataMap = {'test': np.random.randn(200)}
    hist_data = []
    group_labels = []
    for k,v in dataMap.items():
        hist_data.append(v)
        group_labels.append(k)

    # Create distplot
    fig = FF.create_distplot(hist_data, group_labels,bin_size=0.02,curve_type='normal')

    layout = go.Layout(
        annotations=[
            dict(
                x=3,
                y=0,
                xref='x',
                yref='y',
                text='FSGS_UBD',
                showarrow=True,
                arrowhead=2,
                ax=0,
                ay=-100
            ),
        ],
开发者ID:wavefancy,项目名称:BIDMC-PYTHON,代码行数:32,代码来源:DistributionPlotUBD.py

示例10: rain_dist

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_distplot [as 别名]
def rain_dist(path, graph='matplotlib'):

    rain_dist = folder_reader(path)
    rain_dist.columns = ['rain', 'age', 'count']
    no = rain_dist[rain_dist.rain == 'no'][['age', 'count']].set_index('age').sort()
    low = rain_dist[rain_dist.rain == 'low'][['age', 'count']].set_index('age').sort()
    high = rain_dist[rain_dist.rain == 'high'][['age', 'count']].set_index('age').sort()

    if graph == 'matplotlib':
        pylt.figure(figsize=(13, 9))

        pylt.plot((high / rain_dist[rain_dist.rain == 'high']['count'].sum()), label='high rain')
        pylt.plot((low / rain_dist[rain_dist.rain == 'low']['count'].sum()), label='low rain')
        pylt.plot((no / rain_dist[rain_dist.rain == 'no']['count'].sum()), label='no rain')
        pylt.legend(loc='upper right')
        pylt.xlabel('age')
        pylt.ylabel('% of population')
        pylt.grid()
        pylt.show()

    if graph == 'plotly':
        l = low.reset_index()
        h = high.reset_index()
        n = no.reset_index()

        l = l[l.age < 81]
        h = h[h.age < 81]
        n = n[n.age < 81]

        n['count'] = (n['count'] / 1000).astype(int)
        l['count'] = (l['count'] / 10).astype(int)
        h['count'] = (h['count'] / 10).astype(int)

        low_hist = np.repeat(l.age.values, l['count'])
        high_hist = np.repeat(h.age.values, h['count'])
        no_hist = np.repeat(n.age.values, n['count'])

        hist_data = [low_hist]

        group_labels = ['low rain']

        colors = ['rgb(0, 0, 100)']

        # Create distplot with custom bin_size
        fig = FF.create_distplot(hist_data, group_labels, bin_size=1, colors=colors)

        # Plot!
        py.offline.iplot(fig)

        # Add histogram data
        # Group data together
        hist_data = [high_hist]

        group_labels = ['high rain']

        colors = ['rgb(0, 200, 200)']

        # Create distplot with custom bin_size
        fig = FF.create_distplot(hist_data, group_labels, bin_size=1, colors=colors)

        # Plot!
        py.offline.iplot(fig)

        # Add histogram data
        # Group data together
        hist_data = [no_hist]

        group_labels = ['no rain']

        colors = ['rgb(0, 100, 100)']
        # Create distplot with custom bin_size
        fig = FF.create_distplot(hist_data, group_labels, bin_size=1, colors=colors)

        # Plot!
        py.offline.iplot(fig)

        hist_data = [low_hist, high_hist, no_hist]

        group_labels = ['low rain', 'high_rain', 'no rain']

        # Create distplot with custom bin_size
        fig = FF.create_distplot(hist_data, group_labels, bin_size=1)

        # Plot!
        py.offline.iplot(fig)
开发者ID:obr214,项目名称:BD_FinalProject,代码行数:87,代码来源:plot_functions.py


注:本文中的plotly.tools.FigureFactory.create_distplot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。