代码
可以直接运行,风格已经设置好了
import numpy as np
import plotly.graph_objects as go
x = np.linspace(0, 100, 100)
y_pred = np.random.random(100) * 1000
y_truth = np.random.random(100) * 1200
fig = go.Figure()
fig.add_trace(
go.Scatter(
name="Predict",
x=x,
y=y_pred,
mode="markers+lines+text",
marker = dict(size=7, symbol="diamond-open"),
line_color='purple',
#text=area_fire.astype('int'),
textposition="top center"
))
fig.add_trace(
go.Scatter(
name="Reality",
x=x,
y=y_truth,
mode="markers+lines+text",
marker = dict(size=7, symbol="circle"),
line=dict(color='royalblue', width=4, dash='dot'),
line_color='orange',
#text=area_nucleus.astype('int'),
textposition="top center"
))
fig.update_layout(
font=dict(family="Times New Roman",
size=16,
# color="RebeccaPurple",
# weight="bold",
),
title="Xgboost预测结果",
title_x=0.5,
title_y=0.9,
xaxis=dict(title="Sample",
nticks=len(x),
showgrid=True,
showline=True,
showticklabels=True,
gridwidth=1,
# zeroline=True,
tickangle=0,
linecolor = '#636363',
tickfont = dict(
family = '宋体',
size = 14,
color = 'black'
),
tickmode = 'linear',
range=[-1, 30],
tick0 = 1,
dtick = 1),
yaxis=dict(title="Power",
# nticks=,
rangemode="tozero",
linecolor = '#636363',
showgrid=True,
showline=True,
showticklabels=True,
zeroline=True,
gridwidth=1,
tickfont = dict(
family = '宋体',
size = 12,
color = 'black'
)),
legend={
'x': 0.35,
'y': 1.1,
'font': {
'size': 18
},
'orientation': 'h'
},
width=800,
height=500,
template='plotly_white' # plotly_dark plotly_white
)
fig.show()
# fig.write_image(img.png", scale=5)