Plotly express with multiple y-axis

consider the following code

import pandas as pd
import numpy as np
import plotly.express as px

df = pd.DataFrame(
    {'val1':np.random.uniform(low=0.5, high=20, size=(50,)), 
    'val2': np.random.uniform(low=2.5, high=40, size=(50,)),
    'val3': np.random.uniform(low=134.5, high=240, size=(50,)),
    })

fig = px.scatter(df, x = 'val1', y = ['val3', 'val2'])
fig.show()
fig = px.scatter(df, x = 'val1', y = ['val1', 'val2'])
fig.show()
fig = px.scatter(df, x = 'val1', y = ['val1'])
fig.show()
fig = px.scatter(df, x = 'val1', y = 'val1')
fig.show()

The first figure shows as expected two traces. However, the second figures shows only val2. This seems to come from the presence of val1 in the list as figure three is empty. If it is not a list like in figure 4, then everything is fine. wtf?
Has anyone seen that and knows a solution? I want to use the list in a function which gets different y-axis values and sometimes the same as was used for the x-axis.
Plotly version is 5.9.0

Hi @Bernhard welcome to the forums.

Strange indeed, I did not know that. This seems to work too:

fig = px.scatter(x = df.val1, y = [df.val1, df.val2])

The downside is, that you loose the trace names.

Another workaround (pretty ugly and not very satisfying):

import pandas as pd
import numpy as np
import plotly.express as px

# DataFrame
df = pd.DataFrame(
    {'val1':np.random.uniform(low=0.5, high=20, size=(50,)), 
    'val2': np.random.uniform(low=2.5, high=40, size=(50,)),
    'val3': np.random.uniform(low=134.5, high=240, size=(50,)),
    })

# column list  & iterator
column_list = ['val1', 'val2']
column_iterator = iter(column_list)

# create figure
fig = px.scatter(
    x=df['val1'], 
    y=[df[col] for col in column_list]
)

# update trace names
fig.for_each_trace(
    lambda x: x.update({'name': next(column_iterator)})
)