plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

The `size` argument to px.scatter does not accept an integer

Open CarlAndersson opened this issue 4 years ago • 3 comments

According to the documentation, it should be possible to give an integer to the size argument of px.scatter. This does not seem to be the case, and it still tries to use it as a column name. I would expect ot to just set all the markers to the same size. This is useful because sometimes the default value is a bit too small ot too large...

I'm not sure if this is the expected behavior or not, so this could either be a bug report or a feature request 😄

>>> import plotly.express as px
>>> df = px.data.iris()
>>> px.scatter(df, x='sepal_length', y='sepal_width', size=30)
ValueError: Value of 'size' is not the name of a column in 'data_frame'. Expected one of ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species', 'species_id'] but received: 30

CarlAndersson avatar Feb 11 '21 16:02 CarlAndersson

Having the same issue.

Could easily be fixed by checking for type(size), right? Something like this:

if type(size) is int: size = [size] * len(df)

stephantamminga avatar Sep 08 '22 20:09 stephantamminga

Me too. Fix the docs or fix the code?

MichaelTiemannOSC avatar Sep 10 '22 10:09 MichaelTiemannOSC

The size argument does accept an integer, which it uses to look up dataframe columns. If you want to provide an explicit size value, you can use size=px.Constant(30) for example, which under the hood essentially creates a new virtual column filled with 30 and maps that to size.

nicolaskruchten avatar Sep 10 '22 18:09 nicolaskruchten

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

gvwilson avatar Jul 04 '24 13:07 gvwilson