plotly / plotly_express

Plotly Express - Simple syntax for complex charts. Now integrated into plotly.py!
https://plot.ly/python/plotly-express/
MIT License
4 stars 0 forks source link

size column causing error in scatter plot #96

Closed robroc closed 4 years ago

robroc commented 5 years ago

No matter which value I set in the size column of the dataframe, the markers on a scatter plot come out huge. Only the markers on the legend seem to respond.

Likewise, plotting returns this error for each feature drawn:

C:\Users\rochar\AppData\Local\Continuum\miniconda3\envs\data\lib\site-packages\numpy\core\fromnumeric.py:2389: FutureWarning:

Method .ptp is deprecated and will be removed in a future version. Use numpy.ptp instead.

Data frame looks like this:

px

Code used:

import plotly_express as px

px.scatter(df, x='Donations_sum', y="Votes Obtained", color = "Party", 
           facet_row="Election year", size= 'Size', height=1200, width = 700, trendline='ols')

Result:

px2

Environment:

Python 3.6 Jupyter Lab 0.35.4 Plotly Express 0.1.1 Numpy 1.15.4 pandas 0.24.2

Additional comment: it would be nice to set the marker size manually in the function call.

nicolaskruchten commented 5 years ago

So to set the maximum size you can use size_max, and the minimum size today is always zero. This means that if your dataset contains numbers between, say, 30000 and 30500, then all the markers will appear roughly the same size, because they're pretty equally-far from zero.

robroc commented 5 years ago

Oh I see. So if I want all markers to be the same size, I can set any single number on the size column, and make size_max the actual size I want?

nicolaskruchten commented 5 years ago

Ah, sorry, I misunderstood your goal! If you want all the markers to be the same, non-default size, then you should use something like px.scatter(<no need to set size here>).update_traces(marker_size=<whatever>)

Basically the size kwarg in PX is to map to data. If you don't want to map to data then just let PX give you the figure and tweak it afterwards with e.g. .update() or .update_traces()

(we're working on better documentation for this!!)

robroc commented 5 years ago

Now I'm getting this error:

AttributeError: 'ExpressFigure' object has no attribute 'update_traces'

When I try with .update(), it throws a KeyError with marker_size.

nicolaskruchten commented 5 years ago

you'll have to upgrade plotly to 3.9 or 3.10 :)

robroc commented 5 years ago

That did it. Thank you!

Any idea how to get rid of the Numpy FutureWarning?

nicolaskruchten commented 5 years ago

which versions of scipy and statsmodels have you got?

robroc commented 5 years ago

scipy==1.2.1 statsmodels==0.9.0