DOC: use fold transform on loess example
@@ -12,14 +12,17 @@ import numpy as np
np.random.seed(42)
-source = pd.DataFrame(np.cumsum(np.random.randn(100, 3), 0).round(2),
- columns=['A', 'B', 'C'], index=pd.RangeIndex(100, name='x'))
-source = source.reset_index().melt('x', var_name='category', value_name='y')
+source = pd.DataFrame(np.cumsum(np.random.randn(100, 3), 0),
+ columns=['A', 'B', 'C'],
+ index=pd.RangeIndex(100, name='x')).reset_index()
-base = alt.Chart(source).mark_circle(opacity=0.5).encode(
- alt.X('x'),
- alt.Y('y'),
- alt.Color('category')
+base = alt.Chart(source).mark_circle(opacity=0.5).transform_fold(
+ fold=['A', 'B', 'C'],
+ as_=['category', 'y']
+).encode(
+ alt.X('x:Q'),
+ alt.Y('y:Q'),
+ alt.Color('category:N')
)
base + base.transform_loess('x', 'y', groupby=['category']).mark_line(size=4)
