I'm using matplotlib to plot the distribution of a data set, and want to overlay vertical lines for the confidence interval.
The density plot looks fine, but I don't see the line. Any ideas?
# Get data
import urllib.request as request
request.urlretrieve('http://seanlahman.com/files/database/baseballdatabank-master_2016-03-02.zip', "baseballdatabank-master_2016-03-02.zip")
from zipfile import ZipFile
zip = ZipFile('baseballdatabank-master_2016-03-02.zip')
zip.extractall()
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
batting_df = pd.read_csv("baseballdatabank-master\core\Batting.csv")
batting_df = batting_df[batting_df['AB'] > 20]
batting_df['batting_average'] = batting_df['H'] / batting_df['AB']
# Plot distribution
batting_averages = batting_df['batting_average'].dropna()
batting_averages.plot.kde()
# Plot confidence interval
import scipy.stats
import numpy as np, scipy.stats as st
stderr = st.sem(batting_averages)
interval1 = (batting_averages.mean() - stderr * 1.96, batting_averages.mean() + stderr * 1.96)
plt.plot(interval1[0], 12)
plt.show()
I'm trying to plot the vertical line at the x coordinate of the first interval, which is centered around the mean. I passed 12 as the y coordinate as this is highest value shown on the y axis.

plotis unitary. You'll need your kde x as the first argument, and your interval as the y...