代码
from scipy.optimize import curve_fit
from math import sqrt
import plotly.graph_objects as go
import numpy as np
x1 = np.random.random(100) * 100
y1 = np.linspace(500, 1000, 100)
x2 = np.random.random(100) * 150
y2 = np.linspace(1000, 2000, 100)
fig = go.Figure()
fig.add_trace(
go.Scatter(
name="legend 1",
x=x1,
y=y1,
mode="markers",
marker=dict(
color='rgba(120, 110, 90, 1)',
size=12,
symbol="diamond",
# cmin=0,
# cmax=150,
# autocolorscale=True,
# showscale=True,
line=dict(
width=10,
color='rgba(120, 70, 50, 0.3)'
)
),
text="legend 1",
textposition="top center"
))
fig.add_trace(
go.Scatter(
name="legend 2",
x=x2,
y=y2,
mode="markers",
marker=dict(
color='rgba(50, 120, 160, 1)',
size=12,
symbol="circle",
# cmin=0,
# cmax=150,
# colorscale='Electric',
# showscale=True,
line=dict(
width=10,
color='rgba(60, 110, 120, 0.3)'
)
),
text="legend 2",
textposition="top center"
))
fig.update_layout(
font=dict(family="Times New Roman",
size=16,
# color="RebeccaPurple",
),
title="散点示例",
title_x=0.5,
title_y=0.95,
xaxis=dict(title="x轴",
nticks=50,
showgrid=True,
showline=True,
showticklabels=True,
# gridwidth=1,
# zeroline=True,
tickangle=0,
linecolor='#636363',
# tickmode = 'linear'
# tick0 = 0,
# dtick = 1
),
yaxis=dict(title="y轴",
# nticks=50, # y轴刻度数量
tick0=500, # nticks, rangemode 和 range的优先级都比它俩的
dtick=200,
linecolor='#636363',
showgrid=True,
showline=True,
showticklabels=True,
mirror=True, # 是否设置两个Y轴
# range=(0, 2500),
# rangemode="tozero",
zeroline=False,
gridwidth=1,
),
legend={
'x': 0.35,
'y': 1.065,
'font': {
'size': 18
},
'orientation': 'h'
},
width=1000,
height=800,
# paper_bgcolor='rgb(243, 243, 243)',
# plot_bgcolor='rgb(243, 243, 243)',
template='plotly_white' # plotly_dark plotly_white presentation
)
fig.show()
# fig.write_image("第{}组_{}.png".format(num + 1, job_type[index]), scale=5)