:orphan: :html_theme.sidebar_secondary.remove: .. This document is auto-generated by the altair-gallery extension. Do not modify directly. .. _gallery_iowa_electricity: Iowa's Renewable Energy Boom ---------------------------- This example is a fully developed stacked chart using the sample dataset of Iowa's electricity sources. .. altair-plot:: :remove-code: import altair as alt from vega_datasets import data source = data.iowa_electricity() alt.Chart(source, title="Iowa's renewable energy boom").mark_area().encode( x=alt.X( "year:T", title="Year" ), y=alt.Y( "net_generation:Q", stack="normalize", title="Share of net generation", axis=alt.Axis(format=".0%"), ), color=alt.Color( "source:N", legend=alt.Legend(title="Electricity source"), ) ) .. tab-set:: .. tab-item:: Method syntax :sync: method .. code:: python import altair as alt from vega_datasets import data source = data.iowa_electricity() alt.Chart( source, title=alt.Title( "Iowa's green energy boom", subtitle="A growing share of the state's energy has come from renewable sources" ) ).mark_area().encode( alt.X("year:T").title("Year"), alt.Y("net_generation:Q") .title("Share of net generation") .stack("normalize") .axis(format=".0%"), alt.Color("source:N").title("Electricity source") ) .. tab-item:: Attribute syntax :sync: attribute .. code:: python import altair as alt from vega_datasets import data source = data.iowa_electricity() alt.Chart(source, title="Iowa's renewable energy boom").mark_area().encode( x=alt.X( "year:T", title="Year" ), y=alt.Y( "net_generation:Q", stack="normalize", title="Share of net generation", axis=alt.Axis(format=".0%"), ), color=alt.Color( "source:N", legend=alt.Legend(title="Electricity source"), ) )