def test_areaplot(): return alt.vconcat(*map( lambda stack: ar.areaplot( data.iowa_electricity(), x="year", y="net_generation", color="source", stack=stack, ), ar.StackType, ))
width=600, height=200 ) lower = upper.properties( height=60 ).add_selection(brush) upper & lower ## import altair as alt from vega_datasets import data source = data.iowa_electricity() alt.Chart(source).mark_area(opacity=0.3).encode( x="year:T", y=alt.Y("net_generation:Q", stack=None), color="source:N" ) ## import altair as alt from vega_datasets import data source = data.iowa_electricity()
mu = df4.delay.mean() se = 2.58 * (df4.delay.std()/math.sqrt(df4.shape[0])) ub, lb = mu + se, mu - se plt.hlines(mu, -.5, 2.5, ls = '--') plt.hlines([lb, ub], -.5, 2.5,ls =':') plt.xticks(rotation = 0) plt.show() # In[47]: from vega_datasets import data iowa = data.iowa_electricity() iowa.head() # In[48]: iowa.shape # In[49]: iowa.year.value_counts()
""" Trellis Area Chart ------------------ This example shows small multiples of an area chart. """ # category: area charts import altair as alt from vega_datasets import data source = data.iowa_electricity() alt.Chart(source).mark_area().encode( x="year:T", y="net_generation:Q", color="source:N", row="source:N" )
def test_lineplot(): return ar.lineplot(data.iowa_electricity(), x="year", y="net_generation", color="source")
seattle['rained'] = seattle.precipitation > 0 seattle.groupby(seattle.index.month).rained.sum().idxmax() flights = data.flights_20k().set_index('date').sort_index() flights['delay'] = flights.delay.apply(lambda x: 0 if x < 0 else x) flights.groupby(flights.index.hour).delay.mean().idxmax() flights.groupby(flights.index.weekday_name).delay.mean( ) # Yes, Friday > Thursday > Wednesday > Sunday > Tuesday > Saturday > Monday flights.groupby(flights.index.month).delay.mean( ) # Kind of but not really. I'd say it doesn't because the difference in mean times is a minute or so iowa = data.iowa_electricity().set_index('year').sort_index() pivot = iowa.pivot(columns='source', values='net_generation') pivot['totals'] = pivot.sum(axis=1) pivot['fossil_pct'] = pivot['Fossil Fuels'] / pivot.totals pivot['renew_pct'] = pivot['Renewables'] / pivot.totals pivot['nuclear_pct'] = pivot['Nuclear Energy'] / pivot.totals pivot.drop(columns=['totals', 'fossil_pct', 'renew_pct', 'nuclear_pct']).plot() pivot.T pivot[['totals']].plot() # Totals are increasing over time sf['desc'] = pd.qcut(x=sf.temp, q=4, labels=['cold', 'cool', 'warm', 'hot']) cats = pd.get_dummies(sf.desc)