Home > Software design >  Plotting a line between a pair of y coordinates
Plotting a line between a pair of y coordinates

Time:10-07

I am trying to plot the following code where data1, data2, data3 are vectors.

data1 = np.array(means1) 
print('data1=',data1)

data2 = np.array(ci_l) 
print('data2',data2)

data3 = np.array(ci_h) 
print('data3',data3)

x = data1
y = np.concatenate([data2[:,None],data3[:,None]], axis=1)

print('x=', x,'y=',y)

plt.plot(x, [i for (i,j) in y], 'rs', markersize = 4)
plt.plot(x, [j for (i,j) in y], 'bo', markersize = 4)
plt.show()

For each x points as you see in the code I have two y points. When I run the code I obtain the following output:

data1= [[22.8]
 [31.6]
 [27.4]
 [30.4]
 [30.6]]
data2 [[21.80474319]
 [30.60474319]
 [26.40474319]
 [29.40474319]
 [29.60474319]]
data3 [[23.79525681]
 [32.59525681]
 [28.39525681]
 [31.39525681]
 [31.59525681]]
x= [[22.8]
 [31.6]
 [27.4]
 [30.4]
 [30.6]] y= [[[21.80474319]
  [23.79525681]]

 [[30.60474319]
  [32.59525681]]

 [[26.40474319]
  [28.39525681]]

 [[29.40474319]
  [31.39525681]]

 [[29.60474319]
  [31.59525681]]]

and this figure:

enter image description here

My question is how to plot a line that connect each y pair? My problem is similar to this:

< correct plot

  • Related