Closed
Description
This is not a major issue indeed, but I lost quite time until I found where the problem was. About pyplot.errorbar (plot x versus y with error deltas in yerr and xerr) the doc states this about the first optional argument:
xerr/yerr: [ scalar | N, Nx1, or 2xN array-like ] If a scalar number, len(N) array-like
object, or an Nx1 array-like object, errorbars are drawn at +/-value relative to the data.(...)
But in some cases this is not working as expected (or at least, after reading the doc, as I understand it should work). I prepared an example to show where the problems arise (tested with matplotlib 1.4.x, numpy 1.7.1; python 3.3.2):
import numpy as np
import matplotlib.pyplot as plt
x1=np.array([1.2e-05, 1.3e-05, 1.6e-05, 1.7e-05, 1.7e-05])
y1=np.array([6.6e-05, 7.2e-05, 8.9e-05, 9.3e-05, 9.3e-05])
err1=np.array([5.0e-06, 5.0e-06, 5.0e-06, 5.0e-06, 5.0e-06])
print('Data set 1 shape (x1,y1,err1): (%s,%s,%s)' % (x1.shape, y1.shape, err1.shape))
x2=np.array([[ 1.2e-05],
[ 1.3e-05],
[ 1.6e-05],
[ 1.7e-05],
[ 1.7e-05]])
y2=np.array([[ 6.6e-05],
[ 7.2e-05],
[ 8.9e-05],
[ 9.3e-05],
[ 9.3e-05]])
err2=np.array([[ 5.0e-06],
[ 5.0e-06],
[ 5.0e-06],
[ 5.0e-06],
[ 5.0e-06]])
print('Data set 2 shape (x2,y2,err2): (%s,%s,%s)' % (x2.shape, y2.shape, err2.shape))
ax = plt.subplot(141)
ax.set_xscale("log", nonposx='clip')
ax.set_yscale("log", nonposy='clip')
plt.errorbar(x1, y1, yerr=err1) # OK!
ax.set_ylim(ymin=1e-5)
ax = plt.subplot(142)
ax.set_xscale("log", nonposx='clip')
ax.set_yscale("log", nonposy='clip')
plt.errorbar(x2, y2) # Also OK
ax.set_ylim(ymin=1e-5)
ax = plt.subplot(143)
ax.set_xscale("log", nonposx='clip')
ax.set_yscale("log", nonposy='clip')
plt.errorbar(x2, y2, yerr=err2) # Fails!
ax.set_ylim(ymin=1e-5)
ax = plt.subplot(144)
ax.set_xscale("log", nonposx='clip')
ax.set_yscale("log", nonposy='clip')
plt.errorbar(x2, y2, yerr=err1) # also fails
ax.set_ylim(ymin=1e-5)
plt.show()
Thanks!