Same color sequence with marker and line when using addtraces!

# 实验数据散点图
using PlotlyJS
EA_293K = scatter(df, x = :C_EA, y = :q_EA_293K, mode="markers", name = "293K")
EA_303K = scatter(df, x = :C_EA, y = :q_EA_303K, mode="markers", name = "303K")
EA_313K = scatter(df, x = :C_EA, y = :q_EA_313K, mode="markers", name = "313K")
q_EA = plot(
    [EA_293K, EA_303K, EA_313K],
    Layout(
        title = attr(text = "q_EA ~ C_EA", x = 0.5),
        xaxis = attr(title = "C_EA (mg/mL)", dtick = "2"),
        yaxis = attr(title = "q_EA (mg/mL)", dtick = "2")
        )
)

# 回归拟合

function Langmuir(C, p) #   Langmuir 模型
    H, b = p
    q = @. H * C / (1 + b*C )
end
param = []
p0 = [0.1, 0.1]
for col in names(df)[3:2:end]
    xdata = df.C_EA
    ydata = df[:, col] 
    ret = curve_fit(Langmuir, xdata, ydata, p0)
    push!(param, ret.param)
end

param

# 模型曲线visualisation

xdata = collect(3:0.1:13)

for i in 1:length(param)
    addtraces!(q_EA, scatter(x = xdata, y = Langmuir(xdata, param[i]), showlegend = false))
end

q_EA

The color of marker and line mismatch, what should I do?

You can specify the colour of the traces as follows:

C = collect(3:13)

colours = ["purple", "orange", "green"]

EA_1 = scatter(x = C, y = 0.97*C .+ 6.1, mode="markers", marker_color=colours[1], name="1K")
EA_2 = scatter(x = C, y = 0.94*C .+ 5.2, mode="markers", marker_color=colours[2], name="2K")
EA_3 = scatter(x = C, y = 0.97*C .+ 2.8, mode="markers", marker_color=colours[3], name="3K")

q_EA = plot([EA_1, EA_2, EA_3])

add_trace!(q_EA,
    scatter(x = C, y = C .+ 6.0, mode="lines", line_color=colours[1], opacity=0.4, showlegend = false)
)
add_trace!(q_EA,
    scatter(x = C, y = 0.9C .+ 5.0, mode="lines", line_color=colours[2], opacity=0.4, showlegend = false)
)
add_trace!(q_EA,
    scatter(x = C, y = C .+ 2.1, mode="lines", line_color=colours[3], opacity=0.4, showlegend = false)
)

q_EA

1 Like

thanks! :+1:t5: