How to plot confidence interval in Python?

前端 未结 2 2074
猫巷女王i
猫巷女王i 2020-12-09 20:51

I recently started to use Python and I can\'t understand how to plot a confidence interval for a given datum (or set of data). I already have a function that computes, given

2条回答
  •  萌比男神i
    2020-12-09 21:39

    Let's assume that we have three categories and lower and upper bounds of confidence intervals of a certain estimator across these three categories:

    data_dict = {}
    data_dict['category'] = ['category 1','category 2','category 3']
    data_dict['lower'] = [0.1,0.2,0.15]
    data_dict['upper'] = [0.22,0.3,0.21]
    dataset = pd.DataFrame(data_dict)
    

    You can plot the confidence interval for each of these categories using the following code:

    for lower,upper,y in zip(dataset['lower'],dataset['upper'],range(len(dataset))):
        plt.plot((lower,upper),(y,y),'ro-',color='orange')
    plt.yticks(range(len(dataset)),list(dataset['category']))
    

    Resulting with the following graph:

提交回复
热议问题