0

I'm plotting a cumulative distribution of some data following the example in the seaborn documentation:

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

sns.set(style="ticks", color_codes=True)

bins = np.arange(0, 65, 5)
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="day", height=4, aspect=.5)
g = g.map(sns.distplot, "total_bill", bins=bins, hist_kws={"histtype":"stepfilled"})

Now I'd like to get the y values corresponding to each bin. How can I do that?

A similar questions on SO (Get data points from Seaborn distplot) suggests to use get_data() from the plot axis lines.

I tried

for ax in g.axes[:,0]:
    lines = ax.get_lines()

and I get that lines is <a list of 0 Line2D objects>. This means there's no lines to call get_data().

Another question (Python Seaborn Distplot Y value corresponding to a given X value) suggests to use get_height() from the axis patches.

I tried

for ax in g.axes[:,0]:
    values = [h.get_height() for h in ax.patches]

and I get an AttributeError: 'Polygon' object has no attribute 'get_height'. Indeed, I can't see any get_height method in the Polygon matplotlib API.

Ideas?

UPDATE:

After some investigation I found out that having the argument hist_kws={"histtype":"stepfilled"} invalidates the way of getting data from the bars via get_height().

st1led
  • 385
  • 2
  • 4
  • 18

0 Answers0