================ by Jawad Haider
Chpt 4 - Visualization with Matplotlib¶
04 - Basic Errorbars¶
Visualizing Errors¶
For any scientific measurement, accurate accounting for errors is nearly as important, if not more important, than accurate reporting of the number itself.
Basic Errorbars¶
A basic errorbar can be created with a single Matplotlib function call
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
x=np.linspace(0,10,50)
dy=0.8
y=np.sin(x)+dy*np.random.randn(50)
plt.errorbar(x,y,yerr=dy, fmt='k');
Here the fmt is a format code controlling the appearance of lines
In addition to these options, you can also specify horizontal errorbars (xerr), one- sided errorbars, and many other variants. For more information on the options avail‐ able, refer to the docstring of plt.errorbar. ## Continuous Errors In some situations it is desirable to show errorbars on continuous quantities. Though Matplotlib does not have a built-in convenience routine for this type of application, it’s relatively easy to combine primitives like plt.plot and plt.fill_between for a useful result.
#define the model and draw some dataa
model = lambda x: x*np.sin(x)
xdata=np.array([1,3,5,6,8])
ydata=model(xdata)
# computer the Gaussain process fit
gr = GaussianProcessRegressor()
gr.fit(xdata[:,np.newaxis], ydata)
GaussianProcessRegressor()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
GaussianProcessRegressor()