- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Plot 95% confidence interval errorbar Python Pandas dataframes in Matplotlib
To plot 95% confidence interval errorbar Python Pandas dataframes, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Get a dataframe instance of two-dimensional, size-mutable, potentially heterogeneous tabular data.
- Make a dataframe with two columns, category and number.
- Find the mean and std of category and number.
- Plot y versus x as lines and/or markers with attached errorbars.
- To display the figure, use show() method.
Example
import numpy as np import pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame() df['category'] = np.random.choice(np.arange(10), 1000, replace=True) df['number'] = np.random.normal(df['category'], 1) mean = df.groupby('category')['number'].mean() std = df.groupby('category')['number'].std() plt.errorbar(mean.index, mean, xerr=0.5, yerr=2*std, linestyle='--', c='red') plt.show()
Output
Advertisements