0

I am trying to create a distribution for the number of ___ across a few states.

I want to get all of the states on the same graph, represented by different lines.

Here is an example what my data looks like: you have the state ('which I want to filter lines by), the number of reviews (x axis), and the frequency of restaurants that have that many reviews (y axis)

State | num_of_reviews | Count_id
alaska        1              400
alaska        2              388
alaska        3              344
...
Wyoming      57              13

Whenever I try doing a simple line plot in seaborn or matplotlib, it just returns a messy graph.

Does anyone know a string of code where I easily can filter df['State']?

Kbbm
  • 375
  • 2
  • 15

1 Answers1

1

Assuming that you have 50+ states, I wouldn't plot the distribution for each on the same plot as it would get really messy and hard to read. Instead, I would suggest to use a FacetGrid (read more about it here).

Something like this should do.

import seaborn as sns
import matplotlib.pyplot as plt
g = sns.FacetGrid(df, col="State", col_wrap=5, height=1.5)
g = g.map(plt.hist, "num_of_reviews")

You can find other possible solutions and ideas on how to visualize your data here.

If none of these work for you then it might be helpful if you explain a bit better your problem and provide a desired output and a minimal, complete, and verifiable example.

CAPSLOCK
  • 6,243
  • 3
  • 33
  • 56
  • Thank you, a much more logical option! I do get an error when trying to add the argument `height=1.5` however. Is that argument a new one? – Kbbm Apr 25 '19 at 18:52
  • @KyleMcComb nope, it's one of the argument to set the dimension of each facet. from the documentation: *height : scalar, optional Height (in inches) of each facet. See also: aspect. aspect : scalar, optional Aspect ratio of each facet, so that aspect * height gives the width of each facet in inches* – CAPSLOCK Apr 26 '19 at 07:49
  • Well it looks good without the argument, so no worries if i can't get it working. Thank you @gio – Kbbm Apr 26 '19 at 19:52