如何更改 Plotly express 散点图连续色图?

How to change Plotly express scatterplot continuous colormap?

我正在绘制散点图,如附图所示。这里点的大小是基于出现的次数(出现次数越多=点的大小越大)

但是我无法更改图形的颜色图。我尝试对散点图使用连续颜色图关键字,并在 matplotlib 中生成颜色图,然后在 plotly 中使用它,但都没有用。

我正在寻找由黄色(低值)蓝色(中值)和红色(高值)组成的连续色图。

我目前的代码如下:

import pandas as pd
import matplotlib.colors
A= pd.read_csv('example.csv')
dA= A['ML']
dB= A['Radio']
dC= A['Occur']

norm=plt.Normalize(-1,1)
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", 
["yellow","mediumblue","orangered"])

import plotly.express as px

fig = px.scatter(A, x="ML", y="Radio", color="Occur",color_discrete_sequence= 
["red", "blue", "yellow"]
             ,size='Occur')
fig.update_layout(
font_family="Times New Roman",
legend_title_font_color="green" ,
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
xaxis = dict(
    tickmode = 'linear',color= '#000000',
    tick0 = 0,
    dtick = 15
),
yaxis = dict(
    tickmode = 'linear',color= '#000000',
    tick0 = 0,
    dtick = 1
),
font=dict(
    family="Times New Roman",
    size=18,
    color='#000000'
)
)
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True)
fig.update_yaxes(showline=True, linewidth=1, linecolor='black', mirror=True)

连续色图规范为 'color_continuous_scale'。如果此处指定了任何颜色,它将在 plotly 侧进行处理。如果颜色范围是任意设置的,则指定范围值和颜色的元组。数据和代码请参考official reference.

import plotly.express as px
df = px.data.iris()

fig = px.scatter(df,
                 x="sepal_width",
                 y="sepal_length",
                 color='petal_length',
                 color_continuous_scale=[(0,'yellow'), (0.5, 'blue'), (1,'red')],
                 template='plotly_white'
                )

fig.show()