Seaborn Objects: Horizontal line
See original GitHub issueHello.
Firstly, thanks for the addition of seaborn objects. It seems really powerful and easy to use. Awesome!
Secondly, I’d like to ask, whether a functionality is available in the new API. I’d like to draw a horizontal line together with a line derived from data.
For example:
import seaborn.objects as so
from datetime import datetime
import pandas as pd
data = pd.DataFrame({
"date": [datetime(2018, 1, 1), datetime(2018, 2, 1), datetime(2018, 3, 1)],
"count": [250, 130, 300]
})
(
so.Plot(data=data, x="date", y="count")
.add(so.Line())
.add(so.Line(color="grey"), so.Agg())
)
I’d like the second so.Line() to draw a horizontal line that is made out of mean of all values in “count” column. It however averages over automatic groups from “date” column. This functionality (if it isn’t possible already) would be very useful in time-related data, where you would e.g. like to display a yearly average.
It would generally be useful to draw any constant horizontal (or vertical line). Currently the best option that occurs to me is to switch to matplotlib’s axhline.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
I do plan to add a
Rule
mark but it hasn’t happened yet. In the meantime, a little clumsy, but something like this might do?The problem with
by
is that the operation you want is “drop {orient} from the groupers”, otherwise to drop the grouping variable from a more complex plot, you’d have to dowhich is kind of annoying. And it doesn’t really make sense to otherwise choose whether to group by the semantic variable (color, etc.) since you can already drop them by passing
None
in the layer definition.