plotly学习记录

plotly绘图

折线图

import plotly as py 
import plotly.graph_objs as go 

trace0 = go.Scatter( 
x=[1, 2, 3, 4], 
y=[5, 6, 7, 8] 
) 
trace1 = go.Scatter( 
x=[1, 2, 3, 4], 
y=[16, 5, 11, 9] 
) 
fig = go.Figure([trace0,trace1]) 
py.offline.plot(fig, auto_open=True)

C:\Users\于衡\Desktop\plot_image.png

py.offline.plot(fig, auto_open=True,image='png')的image属性可以获得静态图片


折线图,散点图

import plotly as py
import plotly.graph_objs as go
import numpy as np

N = 200
random_x = np.linspace(0, 1, N)
random_y0 = np.random.randn(N)+5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N)-5
trace0 = go.Scatter(
x=random_x,
y=random_y0,
mode='markers',
name='测试1'
)
trace1 = go.Scatter(
x=random_x,
y=random_y1,
mode='markers+lines',
name='测试2'
)
trace2 = go.Scatter(
x=random_x,
y=random_y2,
mode='lines',
name='测试3'
)
fig = go.Figure([trace0, trace1, trace2])
py.offline.plot(fig, auto_open=True,image='png')

C:\Users\于衡\Desktop\plot_image (3).png


3D制图

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

import numpy as np

py.init_notebook_mode(connected=True)
x, y, z = np.random.multivariate_normal(np.array([0, 0, 0]), np.eye(3), 100).transpose()
trace1 = go.Scatter3d(
    x=x,
    y=y,
    z=z,
    mode='markers',
    marker=dict(
        size=12,
        line=dict(
            color='rgba(217, 217, 217, 0.14)',
            width=0.5
        ),
        opacity=0.8
    )
)

x2, y2, z2 = np.random.multivariate_normal(np.array([0, 0, 0]), np.eye(3), 100).transpose()
trace2 = go.Scatter3d(
    x=x2,
    y=y2,
    z=z2,
    mode='markers',
    marker=dict(
        color='rgb(127, 127, 127)',
        size=12,
        symbol='circle',
        line=dict(
            color='rgb(204, 204, 204)',
            width=1
        ),
        opacity=0.9
    )
)
data = [trace1, trace2]
layout = go.Layout(
    margin=dict(
        l=0,
        r=0,
        b=0,
        t=0
    )
)
fig = go.Figure(data=data, layout=layout)
py.plot(fig, filename='simple-3d-scatter', auto_open=True, image='png')

发表评论

电子邮件地址不会被公开。 必填项已用*标注

4 × 1 =