How to change size of point in px.strip plot

How can I change the point size in px.strip plot ?

https://plotly.com/python-api-reference/generated/plotly.express.strip.html

Hi @yogi_dhiman, same approach as in the scatter plot :slight_smile:

fig.update_traces({'marker':{'size': your_desired_size}})

Full example:

import plotly.express as px

df = px.data.tips()
fig = px.strip(df, x='total_bill', y='day')
fig.update_traces({'marker':{'size': 50, 'color': 'pink'}})

creates:

what if want to give size based on some variable
will following work

fig.update_traces({β€˜marker’:{β€˜size’: df[β€˜size’], β€˜color’: df['color]}})

Hi, you can change the marker size and color for each trace:

Hi @yogi_dhiman,

I admit, I got a bit carried away by your question and came up with a scatter strip plot :joy:

What gets lost in this process, is the separation of the data points for a given y-coordinate (in this case the weekday) which is created by px.strip

import plotly.express as px
import plotly.graph_objects as go

# create data
df = px.data.tips()

# calculate relative tip
df['rel_tip'] = df.tip / df.total_bill *100
df.rel_tip = df.rel_tip.apply(round,0)

# set the marker size
#     all relative tips above 25%  --> 30
#     all relative tips above 20% to 25% --> 20
#     rest --> 10
size=[]
for tip, gender in zip(df.rel_tip, df.sex):
    if tip>25:
        size.append(30)
    elif 20<tip<=25:
        size.append(20)
    else:
        size.append(10)

# set marker color, female=gold, male=crimson
color=[['crimson', 'gold'][gender == 'Female'] for gender in df.sex]

# create plotly.graph_objects Figure()  and add trace
figure = go.Figure()
figure.add_scatter(
    x=df.total_bill,
    y=df.day,
    mode='markers',
    marker={'size': size, 'color': color}
    )
figure.update_layout(template='plotly_dark')
figure.show()

creates:

AIMPED i am looking for the point size based on variable value in strip plot itself ( your assumption was correct )
Can we do it ?

Hey @yogi_dhiman, I did not figure out how to do it. Actually I do not think it’s possible. The marker + color argument does not accept iterables. You can see this by switching the chart type:

import plotly.express as px
import numpy as np

# data
df = px.data.tips()

# figure
px_fig = px.strip(df, x='total_bill', y='day')
#px_fig = px.scatter(df, x='total_bill', y='day')

# update marker size
marker_size = np.random.randint(1, 30, df.shape[0])
px_fig.update_traces({'marker':{'size':marker_size}})
1 Like

This is a big limitation of the strip plot, in my opinion. As I have too many points to be displayed, I am clustering them, it would be great to have an indication of the size of each cluster. Colour is not an option in this case, as I have already coloured the markers by using a different property.