yhat / ggpy

ggplot port for python
http://yhat.github.io/ggpy/
BSD 2-Clause "Simplified" License
3.69k stars 573 forks source link

How to overlay a Gaussian to a histogram? #634

Open ggirelli opened 6 years ago

ggirelli commented 6 years ago

I'm trying with not much success to overlay a Gaussian to a histogram. I have two dataframes, one (d) with only x columns for the histogram and another (gauss) with x and y with the Gaussian coordinates.

If I do the following it fails, probably because it still links to the first dataframe...

p = ggplot(aes(x = 'values'), data = d)
p += geom_histogram(binwidth = 0.01, color = 'black')
p += xlim(0, 1)
p += geom_line(aes(x = 'x', y = 'y'), data = gauss)
print(p)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/ggplot/ggplot.py", line 116, in __repr__
    self.make()
  File "/usr/local/lib/python2.7/dist-packages/ggplot/ggplot.py", line 636, in make
    layer.plot(ax, facetgroup, self._aes, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/ggplot/geoms/geom_line.py", line 33, in plot
    (data, _aes) = self._update_data(data, _aes)
  File "/usr/local/lib/python2.7/dist-packages/ggplot/geoms/geom.py", line 43, in _update_data
    data = _aes._evaluate_expressions(self.params['data'])
  File "/usr/local/lib/python2.7/dist-packages/ggplot/aes.py", line 110, in _evaluate_expressions
    raise Exception(msg)
Exception: Invalid column: 'values'
did you mean one of the following: