plotly画图(包含x轴设置marker类型设置)

import numpy as np
import plotly.offline as of
import plotly.graph_objs as go
import plotly.plotly as py
#https://plot.ly/python/reference/#layout-xaxis-zerolinecolor  官方文档
gailv1=[0.0712, 0.1277, 0.1211, 0.1801, 0.0712, 0.088, 0.2824, 0.096, 0.2059, 0.1025, 0.3378, 0.0875, 0.1537, 0.1778, 0.0864, 0.0725, 0.054, 0.1241, 0.1721, 0.1007, 0.1901, 0.0949, 0.0503, 0.2901]
gailv2=[0.0183, 0.1064, 0.1211, 0.1801, 0.017, 0.025, 0.1765, 0.096, 0.0872, 0.0721, 0.0946, 0.0563, 0.0683, 0.0778, 0.016, 0.0213, 0.0373, 0.0966, 0.0505, 0.0432, 0.013, 0.0404, 0.0287, 0.0358]
gailv3=[0.017, 0.0106, 0.0583, 0.0307, 0.0292, 0.0025, 0.0039, 0.0072, 0.0036, 0.0152, 0.0135, 0.0625, 0.0756, 0.0556, 0.0302, 0.03, 0.0553, 0.031, 0.0158, 0.0791, 0.0216, 0.0142, 0.0024, 0.0184]
hours=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
# Create traces
trace0 = go.Scatter(
    x = hours,
    dx=1,
    y = gailv1,
    text=gailv1,
    # fill="tonexty",

    marker={
     'size':10},
    mode='lines+markers',
    name = '1:我们的推荐'


)
trace1 = go.Scatter(
    x = hours,
    dx=1,
    y = gailv2,
    text=gailv2,
    # fill="tonexty",
    # marker='^',  #正三角形
    marker={
     'symbol':4,'size':10},
    mode = 'lines+markers',
    name = '2:最近邻策略推荐'
)
trace2 = go.Scatter(
    x = hours,
    dx=1,
    y = gailv3,
    text=gailv3,
    # fill="tonexty",
    marker={
     'symbol':201,'size':10},
    mode = 'lines+markers',

    name = '3:随机策略推荐'
)

data = [trace0, trace1,trace2]
# 随时间变化的一天中的订单需求量
layout = go.Layout(title='不同方法打车概率的差异',
                  titlefont={
     
                      'size':20
                  },
    xaxis={
     
    'title':'Hour of Day',
    # 'type':'data', #'date'表示日期型坐标轴
    # 'autorange' : False,  #autorange:bool型或'reversed',控制是否根据横坐标对应的数据自动调整坐标轴范围,默认为True
    'showgrid' : False,  #是否显示网格
    'zeroline' : True,  #是否显示基线,即沿着(0,0)画出x轴和y轴
    'titlefont':{
     
        'size':15
    },
    'nticks':24  #x轴最大刻度到24

},yaxis={
     
    'title':'乘客打车成功概率',
    'zeroline' : True,  #是否显示基线,即沿着(0,0)画出x轴和y轴
    'titlefont':{
     
        'size':15
    }
})
fig = go.Figure(data=data, layout=layout)
of.plot(fig)


plotly画图(包含x轴设置marker类型设置)_第1张图片

你可能感兴趣的:(个人学习)