You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I plot an errorbar on a semilogx axis, and there are NaN datapoints in the X data, a ValueError is thrown if the axes is not already initialized. If the axes is already set up, the errorbar is plotted as expected and there is no error.
The ValueError message is:
ValueError: Data has no positive values, and therefore can not be log-scaled.
which is unhelpful, as it is incorrect. Full error chain further down.
This only affects the semilog X axis, not the semilog Y axis.
Example code:
#!/usr/bin/env pythonimportnumpyimportmatplotlibfrommatplotlibimportpyplotprint"matplotlib version:", matplotlib.__version__print"numpy version:", numpy.__version__# Some datax=numpy.arange(0,10,.1)
y1=10**numpy.sin(x)
y2=10**numpy.sin(x)
y2[10] =numpy.nanforiin1,2:
f, ((ax1, ax2), (ax3, ax4)) =pyplot.subplots(nrows=2, ncols=2)
ax1.set_yscale('log')
ax2.set_yscale('log')
ax3.set_xscale('log')
ax4.set_xscale('log')
ax1.errorbar(x, y1, yerr=x/100)
ax1.set_title('semilogy, not nan')
ax2.errorbar(x, y2, yerr=x/100)
ax2.set_title('semilogy, nan')
ax3.errorbar(y1, x, xerr=x/100)
ax3.set_title('semilogx, not nan')
ifi==1:
ax4.plot(y2, x, 'r') # If this is exectured the script runs without errorax4.errorbar(y2, x, xerr=x/100) # if this command initializes the axes a ValueError is thrownax4.set_title('semilogx, nan')
Running this will open two figures, one with four plots, the other with three plots and one empty axes, and then this message in the terminal:
In [29]: runminimum_example.pymatplotlibversion: 1.5.0+441.g3764d42numpyversion: 1.10.1---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
/home/asmund/src/minimum_example.pyin<module>()
33ifi==1:
34ax4.plot(y2, x, 'r') # If this is exectured the script runs without error--->35ax4.errorbar(y2, x, xerr=x/100) # if this command initializes the axes a ValueError is thrown36ax4.set_title('semilogx, nan')
/home/asmund/venv/py2-mplgit/lib/python2.7/site-packages/matplotlib-1.5.0+441.g3764d42-py2.7-linux-x86_64.egg/matplotlib/__init__.pycininner(ax, *args, **kwargs)
1844warnings.warn(msg% (label_namer, func.__name__),
1845RuntimeWarning, stacklevel=2)
->1846returnfunc(ax, *args, **kwargs)
1847pre_doc=inner.__doc__1848ifpre_docisNone:
/home/asmund/venv/py2-mplgit/lib/python2.7/site-packages/matplotlib-1.5.0+441.g3764d42-py2.7-linux-x86_64.egg/matplotlib/axes/_axes.pycinerrorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
2907yo, _=xywhere(y, right, noxlims&everymask)
2908lo, ro=xywhere(left, right, noxlims&everymask)
->2909barcols.append(self.hlines(yo, lo, ro, **lines_kw))
2910ifcapsize>0:
2911caplines.extend(self.plot(lo, yo, 'k|', **plot_kw))
/home/asmund/venv/py2-mplgit/lib/python2.7/site-packages/matplotlib-1.5.0+441.g3764d42-py2.7-linux-x86_64.egg/matplotlib/__init__.pycininner(ax, *args, **kwargs)
1844warnings.warn(msg% (label_namer, func.__name__),
1845RuntimeWarning, stacklevel=2)
->1846returnfunc(ax, *args, **kwargs)
1847pre_doc=inner.__doc__1848ifpre_docisNone:
/home/asmund/venv/py2-mplgit/lib/python2.7/site-packages/matplotlib-1.5.0+441.g3764d42-py2.7-linux-x86_64.egg/matplotlib/axes/_axes.pycinhlines(self, y, xmin, xmax, colors, linestyles, label, **kwargs)
10061007self.update_datalim(corners)
->1008self.autoscale_view()
10091010returncoll/home/asmund/venv/py2-mplgit/lib/python2.7/site-packages/matplotlib-1.5.0+441.g3764d42-py2.7-linux-x86_64.egg/matplotlib/axes/_base.pycinautoscale_view(self, tight, scalex, scaley)
2155x1+=delta2156ifnot_tight:
->2157x0, x1=xlocator.view_limits(x0, x1)
2158self.set_xbound(x0, x1)
2159/home/asmund/venv/py2-mplgit/lib/python2.7/site-packages/matplotlib-1.5.0+441.g3764d42-py2.7-linux-x86_64.egg/matplotlib/ticker.pycinview_limits(self, vmin, vmax)
1608ifminpos<=0ornotnp.isfinite(minpos):
1609raiseValueError(
->1610"Data has no positive values, and therefore can not be "1611"log-scaled.")
1612ValueError: Datahasnopositivevalues, andthereforecannotbelog-scaled.
In [30]:
The text was updated successfully, but these errors were encountered:
tacaswell
added this to the
proposed next point release (2.1) milestone
Nov 22, 2015
This is the auto-scale logic having issues with logscale, which is unfortunately a known issue. In most other cases this just results in really bad limits, not an exception.
Another simple work around is to set ax.set_*scaleafter doing the plotting.
Another, somewhat more sneaky, work around is to use ax4.errorbar(y2, x, xerr=x/100, barsabove=True)
I can reproduce this on Matplotlib version 1.5.3, but not 2.0 or 2.1; I'd recommend upgrading Matplotlib and this should all be working now - please comment if it isn't!
If I plot an errorbar on a semilogx axis, and there are NaN datapoints in the X data, a ValueError is thrown if the axes is not already initialized. If the axes is already set up, the errorbar is plotted as expected and there is no error.
The ValueError message is:
which is unhelpful, as it is incorrect. Full error chain further down.
This only affects the semilog X axis, not the semilog Y axis.
Example code:
Running this will open two figures, one with four plots, the other with three plots and one empty axes, and then this message in the terminal:
The text was updated successfully, but these errors were encountered: