Plotly

可视化神器Plotly(1)---散点图

2019-07-07  本文已影响0人  惑也

一、导入包

# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import plotly.offline as py                    #保存图表,相当于plotly.plotly as py,同时增加了离线功能
py.init_notebook_mode(connected=True)          #离线绘图时,需要额外进行初始化
import plotly.graph_objs as go                 #创建各类图表
import plotly.figure_factory as ff             #创建table

二、参数说明

三、简单散点图

N = 1000
random_x = np.random.randn(N)
random_y = np.random.randn(N)


trace = go.Scatter(
    x = np.random.randn(500),
    y = np.random.randn(500),
    mode = 'markers'
)
data = [trace]

py.iplot(data)

四、风格散点图

trace0 = go.Scatter(
     x = np.random.randn(N),
     y = np.random.randn(N)+3,
     name = 'Above',
     mode = 'markers',
     marker = dict(size = 10, color = 'rgba(152, 0, 0, .8)', line = dict(width = 2, color = 'rgb(0, 0, 0)'))
)
trace1 = go.Scatter(
     x = np.random.randn(N),
     y = np.random.randn(N)-2,
     name = 'Below',
     mode = 'markers',
     marker = dict(size = 10, color = 'rgba(255, 182, 193, .9)', line = dict(width = 2))
)
data = [trace0, trace1]

layout = dict(title = '风格散点图', yaxis = dict(zeroline = False), xaxis = dict(zeroline = False))
fig = dict(data=data, layout=layout)
py.iplot(fig)

五、增加颜色刻度条

trace1 = go.Scatter(
     y = np.random.randn(500),
     mode='markers',
     marker=dict(size=16, color = np.random.randn(500), colorscale='Viridis', showscale=True)
)
data = [trace1]

py.iplot(data)
上一篇下一篇

猜你喜欢

热点阅读