import numpy as np
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import matplotlib.ticker as ticker
# whiteout outside the plot
#f.patch.set_facecolor('white')
plt.rcParams['axes.facecolor']='w'
x = range(15)
plt.plot(x,x, '.')
[<matplotlib.lines.Line2D at 0x7fcc3a291750>]
plt.errorbar(x,x,yerr=3.0,fmt=".")
plt.yticks(np.arange(min(x), max(x)+1, 10.0))
([<matplotlib.axis.YTick at 0x7fcc3a55efd0>, <matplotlib.axis.YTick at 0x7fcc3a55ea50>], [Text(0, 0, ''), Text(0, 0, '')])
So that's pretty close but still a continuous line and not exactly what we want. This is the hard part. We are going to have to manually plot all the error bars with a custom function.
fig, ax = plt.subplots()
plt.plot(0.5,0.5, 'o')
plt.axvline(0.5,ymin=0.2,ymax=0.4)
plt.axvline(0.5,ymin=0.6,ymax=0.8)
<matplotlib.lines.Line2D at 0x7fcc3a5be390>
The functions below require Matlpotlib v3.3
# for a standard error
x = range(15)
y = x
yerr = 6.0
s_factor = 0.5
fig, ax = plt.subplots()
plt.plot(x,y, '.')
for x_i,y_i in zip(x,y):
x1, y1 = [x_i, x_i], [(y_i + s_factor*yerr/2), (y_i + yerr/2)]
x2, y2 = [x_i, x_i], [(y_i - s_factor*yerr/2), (y_i - yerr/2)]
plt.plot(x1, y1, marker = '')
plt.plot(x2, y2, marker = '')
plt.yticks(np.arange(min(x), max(x)+1, 10.0))
plt.xlabel('x-axis')
plt.ylabel('y-axis')
Text(0, 0.5, 'y-axis')
# for non-standard error
x = range(15)
y = x
yerr = 5.0 * np.random.randn(15)
s_factor = 0.4
fig, ax = plt.subplots()
plt.plot(x,y, '.', markersize=6, zorder=2)
for x_i,y_i,yerr_i in zip(x,y,yerr):
x1, y1 = [x_i, x_i], [(y_i + s_factor*yerr_i/2), (y_i + yerr_i/2)]
x2, y2 = [x_i, x_i], [(y_i - s_factor*yerr_i/2), (y_i - yerr_i/2)]
plt.plot(x1, y1, marker = '', color='lightgray', zorder=1)
plt.plot(x2, y2, marker = '', color='lightgray', zorder=1)
plt.yticks(np.arange(min(x), max(x)+5, 10.0))
plt.xlabel('x-axis')
plt.ylabel('y-axis')
# remove tick labels?
# frame1 = plt.gca()
# frame1.axes.xaxis.set_ticklabels([])
# frame1.axes.yaxis.set_ticklabels([])
#plt.savefig("mini-box.png", dpi=200, bbox_inces="tight")
Text(0, 0.5, 'y-axis')