Appearance
Altair
PyConsole supports visualization with altair
Usage
Steps
- import altair and data
python
import altair as alt
from vega_datasets import data
- make a plot
Create chart object
python
source = data.ohlc()
open_close_color = (
alt.when("datum.open <= datum.close")
.then(alt.value("#06982d"))
.otherwise(alt.value("#ae1325"))
)
base = alt.Chart(source).encode(
alt.X('date:T')
.axis(format='%m/%d', labelAngle=-45)
.title('Date in 2009'),
color=open_close_color
)
rule = base.mark_rule().encode(
alt.Y('low:Q')
.title('Price')
.scale(zero=False),
alt.Y2('high:Q')
)
bar = base.mark_bar().encode(
alt.Y('open:Q'),
alt.Y2('close:Q')
)
- show the plot by calling
.show
method on the chart
python
(rule + bar).show()