🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Best way to create a Categorical scatter plot

I am trying to find a nice way to display categorical data in Plotly. Though I can essentially do this in Plotly I run into the issue of overlapping points. Seaborn has a nice way of doing this (https://seaborn.pydata.org/tutorial/categorical.html) by having points that would otherwise overlap move slightly to the left and right.

I can’t seem to find this sort of functionality in Plotly. To work around this I will create an invisible secondary x axis which I will then get to mirror the positions of the categorical data. I will then plot the points of this which will allow me to move them if data is repeated. However this seems like a bit of a hassle so if Plotly actually has anything built in that would be great to know.

1 Like

@OliverBrace, plotly box plots have the ability to display a jittered scatter plot next to the box summary of the distribution. Maybe that can do what you need. See an example here.

Bingo. That looks like exactly what I need. However is the jitter random. I would rather the graph look exactly the same every time it is run and not just similar. (Though I can just run it to find out myself)

Regardless thank you for your help.

It seems like jitter is only available when used in conjunction with a boxplot. Is this correct or am I missing something. My data is a scatter plot (That uses categorical data). Trying to run this returns " ‘jitter’ is not allowed in ‘scatter’ "

1 Like

Yeah, as far as I know this option only works in conjunction with a box plot or a violin plot and there doesn’t seem to be a way to display only the points.

1 Like

Ah thats a shame. I guess Ill just have to create a work around. Thanks for the help

I’d be interested in this too after doing these in Seaborn, did you find a solution?

1 Like

So I eventually created a dirty work around (because the question was not answered).

I created a function that counted the amount of times a point appeared in the same place. So if it had the same category and the same value then it would add one to a hidden value.

I then used this to draw what I wanted

It was very nasty but I had no other way of doing it.

1 Like