khalido.org
I love me some subheader text.
Table of contents.

Blogging with Jupyter notebooks

Viz

There are a ton of viz libraries, I am going to start with two:

Using a simple cars dataset:

df = data.cars()
df.head()

Name Miles_per_Gallon Cylinders Displacement Horsepower Weight_in_lbs Acceleration Year Origin
0 chevrolet chevelle malibu 18.0 8 307.0 130.0 3504 12.0 1970-01-01 USA
1 buick skylark 320 15.0 8 350.0 165.0 3693 11.5 1970-01-01 USA
2 plymouth satellite 18.0 8 318.0 150.0 3436 11.0 1970-01-01 USA
3 amc rebel sst 16.0 8 304.0 150.0 3433 12.0 1970-01-01 USA
4 ford torino 17.0 8 302.0 140.0 3449 10.5 1970-01-01 USA

Altair

The below chart should stay interactive in the browser, with zoom and tooltips:

Code details ...

#collapse-show
alt.Chart(df).mark_circle(size=60).encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
    tooltip=['Name', 'Origin', 'Horsepower', 'Miles_per_Gallon']
).interactive()

Code details ...

#collapse-show
alt.Chart(df).mark_line().encode(
    alt.X('Year:T', timeUnit='year'),
    alt.Y('Miles_per_Gallon:Q', aggregate='mean'),
    alt.Color('Origin:N')
).properties(
    title=" average MPG by origin over time",
    width=450,
    height=150
)

Code details ...

#collapse-show
line = alt.Chart(df).mark_line().encode(
    x='Year',
    y='mean(Miles_per_Gallon)'
).properties(
    title="Line with CI using Altair"
)

band = alt.Chart(df).mark_errorband(extent='ci').encode(
    x='Year',
    y=alt.Y('Miles_per_Gallon', title='Miles/Gallon'),
)

band + line

Matplotlib

sns.set(style="white")
fig, ax = plt.subplots(figsize=(10,4))
ax.set_title("Line with CI")
sns.lineplot(x="Year", y="Miles_per_Gallon", ci=95, data=df, ax=ax);

svg

Other Stuff

Emojis:

Images

This here ahould be an animated gif:

posted , updated
tagged: python