diff --git a/source/inference.md b/source/inference.md index f2a7c13a..735cbc45 100755 --- a/source/inference.md +++ b/source/inference.md @@ -1122,11 +1122,12 @@ the true sampling distribution—which corresponds to taking many samples fr ```{code-cell} ipython3 :tags: [remove-input] +sampling_distribution.encoding.x['bin']['extent'] = (90, 250) alt.vconcat( alt.layer( sampling_distribution, - sampling_distribution.mark_rule(color='#f58518', size=2).encode(x='mean(mean_price)', y=alt.Y()), - sampling_distribution.mark_text(color='#f58518', size=12, align='left', dx=16, fontWeight='bold').encode( + alt.Chart(sample_estimates).mark_rule(color='#f58518', size=2).encode(x='mean(mean_price)'), + alt.Chart(sample_estimates).mark_text(color='#f58518', size=12, align='left', dx=16, fontWeight='bold').encode( x='mean(mean_price)', y=alt.value(7), text=alt.value(f"Mean = {sampling_distribution['data']['mean_price'].mean().round(1)}") @@ -1134,15 +1135,13 @@ alt.vconcat( ).properties(title='Sampling distribution', height=150), alt.layer( boot_est_dist, - boot_est_dist.mark_rule(color='#f58518', size=2).encode(x='mean(mean_price)', y=alt.Y()), - boot_est_dist.mark_text(color='#f58518', size=12, align='left', dx=18, fontWeight='bold').encode( + alt.Chart(boot20000_means).mark_rule(color='#f58518', size=2).encode(x='mean(mean_price)'), + alt.Chart(boot20000_means).mark_text(color='#f58518', size=12, align='left', dx=18, fontWeight='bold').encode( x='mean(mean_price)', - y=alt.value(6), + y=alt.value(7), text=alt.value(f"Mean = {boot_est_dist['data']['mean_price'].mean().round(1)}") ) ).properties(title='Bootstrap distribution', height=150) -).resolve_scale( - x='shared' ) ``` @@ -1252,18 +1251,19 @@ visualize the interval on our distribution in {numref}`fig:11-bootstrapping9`. ```{code-cell} ipython3 # Create the annotation for for the 2.5th percentile -text_025 = alt.Chart().mark_text( +rule_025 = alt.Chart().mark_rule(color='#f58518', size=3, strokeDash=[5]).encode( + x=alt.datum(ci_bounds[0.025]) +).properties( + width=500 +) +text_025 = rule_025.mark_text( color='#f58518', size=12, fontWeight='bold', dy=-160 ).encode( - x=alt.datum(ci_bounds[0.025]), text=alt.datum(f'2.5th percentile ({ci_bounds[0.025].round(1)})') -).properties( - width=500 ) -rule_025 = text_025.mark_rule(color='#f58518', size=3, strokeDash=[5]) # Create the annotation for for the 97.5th percentile text_975 = text_025.encode( diff --git a/source/viz.md b/source/viz.md index b42095c1..c3323467 100755 --- a/source/viz.md +++ b/source/viz.md @@ -1554,13 +1554,14 @@ We also reduce the height of each chart so that they all fit in the same view. Note that we are re-using the chart we created just above, instead of re-creating the same chart from scratch. +We also explicitly specify that `facet` is a categorical variable +since faceting should only be done with categorical variables. ```{code-cell} ipython3 - morley_hist_facet = morley_hist_categorical.properties( height=100 ).facet( - "Expt", + "Expt:N", columns=1 ) ``` @@ -1626,7 +1627,7 @@ v_line = alt.Chart(morley_df).mark_rule(strokeDash=[5], size=2).encode( morley_hist_relative = (morley_hist_rel + v_line).properties( height=100 ).facet( - "Expt", + "Expt:N", columns=1, title="Histogram of relative error of Michelson’s speed of light data" ) @@ -1719,7 +1720,7 @@ morley_hist_default = alt.Chart(morley_df).mark_bar().encode( morley_hist_max_bins = alt.vconcat( alt.hconcat( (morley_hist_default + v_line).facet( - 'Expt', + 'Expt:N', columns=1, title=alt.TitleParams('Default (bin=True)', fontSize=16, anchor='middle', dx=15) ), @@ -1730,7 +1731,7 @@ morley_hist_max_bins = alt.vconcat( title="Relative error (%)" ) ) + v_line).facet( - 'Expt', + 'Expt:N', columns=1, title=alt.TitleParams('maxbins=5', fontSize=16, anchor='middle', dx=15) ), @@ -1743,7 +1744,7 @@ morley_hist_max_bins = alt.vconcat( title="Relative error (%)" ) ) + v_line).facet( - 'Expt', + 'Expt:N', columns=1, title=alt.TitleParams('maxbins=70', fontSize=16, anchor='middle', dx=15) ), @@ -1754,7 +1755,7 @@ morley_hist_max_bins = alt.vconcat( title="Relative error (%)" ) ) + v_line).facet( - 'Expt', + 'Expt:N', columns=1, title=alt.TitleParams('maxbins=200', fontSize=16, anchor='middle', dx=15) )