精华内容
下载资源
问答
  • Plotly

    2020-08-14 17:16:44
    plotly官网 https://github.com/tpof314/plotly_examples 安装 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple plotly import plotly plotly.__version__ import pandas as pd data = pd.read_csv('C:\\...

    简单学一下

    官网例子
    plotly官网

    https://github.com/tpof314/plotly_examples

    安装

    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple plotly
    
    import plotly
    plotly.__version__
    import pandas as pd
    data = pd.read_csv('C:\\Users\\Administrator\\Desktop\\plotly_examples-master\\data\\nz_weather.csv')
    data.head()
    import plotly.graph_objects as go
    
    line1 = go.Scatter(x=data['DATE'], y=data['Auckland'], name='Auckland')
    fig  = go.Figure(line1)
    fig.show()
    

    在这里插入图片描述

    line1 = go.Scatter(x=data['DATE'], y=data['Auckland'], name='Auckland')
    line2 = go.Scatter(x=data['DATE'], y=data['Wellington'], name='Wellington')
    fig  = go.Figure([line1, line2])
    fig.update_layout(
        title = "New Zealand Weather",
        xaxis_title = "Date",
        yaxis_title = "Weather"
    )
    fig.show()
    

    在这里插入图片描述
    条形图

    data_2010 = data[(data['DATE'] >= '2010-01') & (data['DATE'] < '2011-01')]
    data_2010
    bar1 = go.Bar(x = data_2010['DATE'], y = data_2010['Auckland'], 
                  text = data_2010['Auckland'], textposition='outside')
    fig = go.Figure(bar1)
    fig.show()
    

    在这里插入图片描述

    bar1 = go.Bar(x = data_2010['DATE'], y = data_2010['Auckland'], 
                  text = data_2010['Auckland'], textposition='outside', name='Auckland')
    bar2 = go.Bar(x = data_2010['DATE'], y = data_2010['Wellington'], 
                  text = data_2010['Wellington'], textposition='outside', name='Wellington')
    fig = go.Figure([bar1, bar2])
    fig.show()
    

    在这里插入图片描述
    直方图Histogram

    hist = go.Histogram(x = data['Auckland'])
    fig = go.Figure(hist)
    fig.update_layout()
    fig.show()
    

    在这里插入图片描述

    hist = go.Histogram(x = data['Auckland'])
    fig = go.Figure(hist)
    fig.update_layout(bargap=0.1)
    fig.show()
    

    在这里插入图片描述

    hist = go.Histogram(x = data['Auckland'], xbins={'size': 10})
    fig = go.Figure(hist)
    fig.update_layout(bargap=0.1)
    fig.show()
    

    在这里插入图片描述

    import plotly.graph_objects as go
    import pandas as pd
    data = pd.read_csv('./data/iris.csv')
    data.head()
    
    points = go.Scatter(x = data['SepalLength'], y = data['SepalWidth'], mode='markers')
    fig = go.Figure(points)
    fig.show()
    

    在这里插入图片描述

    import plotly.express as px
    fig = px.scatter(data, x = 'SepalLength', y = 'SepalWidth',
                    color='Name')
    fig.show()
    

    在这里插入图片描述

    fig = px.scatter_matrix(data, dimensions=['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'],
                            color='Name')
    fig.show()
    

    在这里插入图片描述
    3D图

    import plotly.graph_objects as go
    import pandas as pd
    data = pd.read_csv('C:\\Users\\Administrator\\Desktop\\plotly_examples-master\\data\\iris.csv')
    data.head()
    

    在这里插入图片描述

    line = go.Scatter(x = data['x'], y = data['y'])
    fig = go.Figure(line)
    fig.show()
    

    在这里插入图片描述

    line = go.Scatter3d(x = data['x'], y = data['y'], z = data['z'])
    fig = go.Figure(line)
    fig.show()
    

    在这里插入图片描述

    line = go.Scatter3d(x = data['x'], y = data['y'], z = data['z'], mode='markers')
    fig = go.Figure(line)
    fig.show()
    

    在这里插入图片描述

    line = go.Scatter3d(x = data['x'], y = data['y'], z = data['z'], 
                        mode='markers', marker={'size': 3, 'color': 'red'})
    fig = go.Figure(line)
    fig.show()
    

    在这里插入图片描述
    plotly.express

    import plotly.express as px
    fig = px.scatter_3d(data, x='x', y='y', z='z', color='color')
    fig.show()
    

    在这里插入图片描述
    曲面

    import plotly.graph_objects as go
    import pandas as pd
    data = pd.read_csv('C:\\Users\\Administrator\\Desktop\\plotly_examples-master\\data\\mt_bruno_elevation.csv')
    del data['index']
    

    在这里插入图片描述

    height = data.values
    surface = go.Surface(z = height)
    fig = go.Figure(surface)
    fig.show()
    

    在这里插入图片描述

    import numpy as np
    x = np.arange(-5, 6)
    y = np.arange(-5, 6)
    xv, yv = np.meshgrid(x, y)
    xv
    '''
    array([[-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5],
           [-5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5]])
    '''
    
    yv
    '''
    array([[-5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5],
           [-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4],
           [-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3],
           [-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2],
           [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
           [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
           [ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1],
           [ 2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2],
           [ 3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3],
           [ 4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4],
           [ 5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5]])
    '''
    
    
    z = xv**2 + yv**2
    z
    '''
    array([[50, 41, 34, 29, 26, 25, 26, 29, 34, 41, 50],
           [41, 32, 25, 20, 17, 16, 17, 20, 25, 32, 41],
           [34, 25, 18, 13, 10,  9, 10, 13, 18, 25, 34],
           [29, 20, 13,  8,  5,  4,  5,  8, 13, 20, 29],
           [26, 17, 10,  5,  2,  1,  2,  5, 10, 17, 26],
           [25, 16,  9,  4,  1,  0,  1,  4,  9, 16, 25],
           [26, 17, 10,  5,  2,  1,  2,  5, 10, 17, 26],
           [29, 20, 13,  8,  5,  4,  5,  8, 13, 20, 29],
           [34, 25, 18, 13, 10,  9, 10, 13, 18, 25, 34],
           [41, 32, 25, 20, 17, 16, 17, 20, 25, 32, 41],
           [50, 41, 34, 29, 26, 25, 26, 29, 34, 41, 50]])
    '''
    
    surface = go.Surface(x = xv, y = yv, z = z)
    fig = go.Figure(surface)
    fig.show()
    

    在这里插入图片描述
    地图

    import plotly.graph_objects as go
    import pandas as pd
    data = pd.read_csv('C:\\Users\\Administrator\\Desktop\\plotly_examples-master\\data\\earthquakes.csv')
    data.head()
    

    在这里插入图片描述

    my_map = go.Densitymapbox(lat=data['Latitude'], lon=data['Longitude'], z=data['Magnitude'], radius=4)
    fig = go.Figure(my_map)
    fig.update_layout(mapbox_style="open-street-map")
    fig.show()
    

    在这里插入图片描述
    饼图

    import plotly.express as px
    
    # 准备数据
    df = px.data.gapminder().query("year == 2007").query("continent == 'Europe'")
    df.loc[df['pop'] < 2.e6, 'country'] = 'Other countries' # Represent only large countries
    df.head()
    

    在这里插入图片描述

    fig = px.pie(df, values='pop', names='country', title='Population of European continent')
    fig.show()
    

    在这里插入图片描述

    import plotly.express as px
    # This dataframe has 244 lines, but 4 distinct values for `day`
    df = px.data.tips()
    df
    

    在这里插入图片描述

    fig = px.pie(df, values='tip', names='day')
    fig.show()
    

    在这里插入图片描述
    设置颜色

    import plotly.express as px
    df = px.data.tips()
    fig = px.pie(df, values='tip', names='day', color_discrete_sequence=px.colors.sequential.RdBu)
    fig.show()
    

    在这里插入图片描述
    Sunburst charts

    import plotly.graph_objects as go
    
    fig =go.Figure(go.Sunburst(
        labels=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
        parents=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
        values=[10, 14, 12, 10, 2, 6, 6, 4, 4],
    ))
    fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))
    
    fig.show()
    

    在这里插入图片描述

    import plotly.express as px
    df = px.data.tips()
    fig = px.sunburst(df, path=['day', 'time', 'sex'], values='total_bill')
    fig.show()
    

    在这里插入图片描述

    展开全文
  • plotly

    千次阅读 2019-10-27 16:10:16
    在线初始化 module 'plotly.tools' has no attribute 'set_credentials_file' https://www.cnblogs.com/zzqingwenn/p/11305814.html ImportError: The plotly.plotl...

    https://chart-studio.plot.ly/settings/api

     

    在线初始化

    module 'plotly.tools' has no attribute 'set_credentials_file'

    https://www.cnblogs.com/zzqingwenn/p/11305814.html

     

    ImportError:
    The plotly.plotly module is deprecated,
    please install the chart-studio package and use the
    chart_studio.plotly module instead. 

    import plotly.plotly as py 改成 

    展开全文

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 5,170
精华内容 2,068
关键字:

plotly