an array from genfromtxt is being passed as a sequence?
<p>I have a list of coordinates and their respective error values in the shape:</p>

<pre><code># Graph from standard correlation, page 1
1.197   0.1838  -0.03504    0.07802 +-0.006464  +0.004201
1.290   0.2072  -0.04241    0.05380 +-0.005833  +0.008101
</code></pre>

<p>where the columns denote <code>x,y,lefterror,righterror,buttomerror,toperror</code>I load the file as <code>error=np.genfromtxt("standard correlation.1",skip_header=1)</code> and finally I try to graph this as</p>

<pre><code>xerr=error[:,2:4]
yerr=error[:,4:]
x=error[:,0]
y=error[:,1]
plt.errorbar(x,y,xerr=xerr,yerr=yerr,fmt='')
</code></pre>

<p>Which yells a <code>ValueError: setting an array element with a sequence.</code>when I try to run it, I understand this error is given when you're passing an object such a a list to an argument that's expecting a numpy array object, I am clueless as to how I should fix this problem, as np.genfromtxt should always return an ndarray.</p>

<p>Thanks for your help.</p>

<p><strong>Edit:</strong> I changed the file to remove the '+' character, as reading '+-' would yield NaN values in the bottom error column, but I still get the same error.  </p>

<p>The shape of the array numpy expects for individual errorbars is <code>(2, N)</code>. You therefore need to transpose your array <code>error[:,2:4].T</code>
Also, <code>matplotlib.errorbar</code> understands those values relative to the data. If <code>x</code> is the value and <code>(xmin, xmax)</code> the corresponding error, the errorbar goes from <code>x-xmin</code> to <code>x+xmax</code>. You therefore shouldn't have negative values in the errorbar arrays.</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt

f = "1   0.1  0.05    0.1 0.005  0.01" + \
   " 1.197   0.1838  -0.03504    0.07802 -0.006464  0.004201 " + \
   " 1.290   0.2072  -0.04241    0.05380 -0.005833  0.008101" 
error=np.fromstring(f, sep=" ").reshape(3,6)
print error
#[[ 1.        0.1       0.05      0.1       0.005     0.01    ]
# [ 1.197     0.1838   -0.03504   0.07802  -0.006464  0.004201]
# [ 1.29      0.2072   -0.04241   0.0538   -0.005833  0.008101]]

xerr=np.abs(error[:,2:4].T)
yerr=np.abs(error[:,4:].T)
x=error[:,0]
y=error[:,1]
plt.errorbar(x,y,xerr=xerr,yerr=yerr,fmt='')
plt.show()
</code></pre>

<p>Concerning the value error, it may have been caused by the <code>+-</code> issue.</p>

python arrays numpy matplotlib errorbar