Here's a plot I made using matplotlib
. It uses the bar
and scatter
methods from pylab
.
I have 3 issues:
How to make the error bars fatter? No API in bar
for this that I can see.
How to specify the axes properly?
How to stop the x-axis labels from showing?
The first is most important, as I have no idea. I guess one more thing would be, how to display the image here in SO? I've seen it done but don't know how.
Here is the code:
import numpy as np
from pylab import *
data1 = np.linspace(12,22,7)
data2 = np.random.normal(loc=15,scale=5,size=10)
data3 = [11,12,18,19,20,26,27]
data = [data1,np.abs(data2),data3]
# n = number of groups
def layout(n,r=7):
s = r**2 # r = radius of each data point
#layout from 1 to 100
margin = 5
spacer = 10
group_width = (100 - 2*margin - (n-1)*spacer)*1.0/n
dot_width = r
bar_width = group_width - dot_width
current = margin
rL = list()
for i in range(n):
rL.append(current) # x for point
rL.append(current + 3) # x for bar
current += group_width + spacer
return s, bar_width, rL
s, w, xlocs = layout(len(data))
for group in data:
x = xlocs.pop(0)
for e in group:
scatter(x,e,s=s,color='k')
m = np.mean(group)
e = np.std(group)
x = xlocs.pop(0)
o = bar(x,m,width=w,color='0.6',
yerr=e, ecolor='k')
show()