sherpa
sherpa copied to clipboard
inconsistent warning for axis limits when using log scale (set_xlog/ylog) for plots with matplotlib
This is not a lien on the 4.11 release.
With the CIAO 4.11 code base (so close to master
) and matplotlib version 2.2.3, I see the following behavior, where some, but not all calls to plot data/model/residuals/... leads to the following warning after calling set_xlog
:
UserWarning: Attempted to set non-positive xlimits for log-scale axis; invalid limits will be ignored.
'Attempted to set non-positive xlimits for log-scale axis; '
Note that the presence of the warnings is inconsistent (ie I would expect it to happen all times or no times) but is consistent (in that it happens after a particular sequence of plot calls). My guess is that we are not clearing up the state from the previous plot correctly, but I haven't looked into the code.
Also note that the warning doesn't really make sense, since the data is > 0 for both axes.
% ipython --matplotlib
Python 3.5.4 (default, Sep 14 2018, 15:42:52)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
Using matplotlib backend: TkAgg
In [1]: from sherpa.astro import ui
In [2]: ui.load_arrays(1, [0.2, 2, 20], [200, 20, 0.2])
In [3]: ui.set_source(ui.const1d.mdl)
In [4]: ui.plot_fit()
In [5]: ui.plot_fit_resid()
In [6]: ui.plot_fit()
In [7]: ui.plot_fit_resid()
In [8]: set_xlog()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-8-1dd939fa3894> in <module>()
----> 1 set_xlog()
NameError: name 'set_xlog' is not defined
In [9]: ui.set_xlog()
In [10]: ui.plot_fit()
In [11]: ui.plot_fit_resid()
In [12]: ui.plot_fit()
/home/djburke/testlocal/ciaot/ciao-4.11/ots/lib/python3.5/site-packages/matplotlib/axes/_base.py:3157: UserWarning: Attempted to set non-positive xlimits for log-scale axis; invalid limits will be ignored.
'Attempted to set non-positive xlimits for log-scale axis; '
In [13]: ui.plot_fit()
In [14]: ui.plot_fit()
In [15]: ui.plot_fit_resid()
In [16]: ui.plot_fit_resid()
/home/djburke/testlocal/ciaot/ciao-4.11/ots/lib/python3.5/site-packages/matplotlib/axes/_base.py:3157: UserWarning: Attempted to set non-positive xlimits for log-scale axis; invalid limits will be ignored.
'Attempted to set non-positive xlimits for log-scale axis; '
In [17]: ui.plot_fit_resid()
/home/djburke/testlocal/ciaot/ciao-4.11/ots/lib/python3.5/site-packages/matplotlib/axes/_base.py:3157: UserWarning: Attempted to set non-positive xlimits for log-scale axis; invalid limits will be ignored.
'Attempted to set non-positive xlimits for log-scale axis; '
In [18]: ui.plot_fit_resid()
/home/djburke/testlocal/ciaot/ciao-4.11/ots/lib/python3.5/site-packages/matplotlib/axes/_base.py:3157: UserWarning: Attempted to set non-positive xlimits for log-scale axis; invalid limits will be ignored.
'Attempted to set non-positive xlimits for log-scale axis; '
In [19]: ui.plot_fit()
/home/djburke/testlocal/ciaot/ciao-4.11/ots/lib/python3.5/site-packages/matplotlib/axes/_base.py:3157: UserWarning: Attempted to set non-positive xlimits for log-scale axis; invalid limits will be ignored.
'Attempted to set non-positive xlimits for log-scale axis; '
In [20]: ui.plot_fit_resid()
In [21]:
You can replicate this with
import numpy as np
from sherpa.data import Data1D
from sherpa import plot
from matplotlib import pyplot as plt
d = Data1D('xmpl', np.asarray([0.2, 2, 20]), np.asarray([200, 20, 0.2]))
dplot = plot.DataPlot()
dplot.prepare(d)
dplot.plot_prefs['xlog'] = True
jplot = plot.JointPlot()
jplot.plottop(dplot)
plt.clf()
If you construct a ModelPlot
and send it to plottop
instead then you don't see the warning. I believe it may be because here we call the matplotlib errorbar
routine with both xerr
and yerr
as None
.
Actually, it may be just xerr=None
in errorbar
since if you add (before the creation of dplot
)
d.staterror = np.asarray([10, 1, 0.1])
then you still get the same warning (which makes sense as the message is about the x axis and it's the x axis that is tied together between the two plots).
@DougBurke is this still an issue? I do not get an error in the 4.12.1 candidate release in ciao.
With the example above I still see an issue with the master branch:
% cat p.py
import numpy as np
from sherpa.data import Data1D
from sherpa import plot
from matplotlib import pyplot as plt
d = Data1D('xmpl', np.asarray([0.2, 2, 20]), np.asarray([200, 20, 0.2]))
dplot = plot.DataPlot()
dplot.prepare(d)
dplot.plot_prefs['xlog'] = True
jplot = plot.JointPlot()
jplot.plottop(dplot)
plt.clf()
then
$ python p.py
p.py:15: UserWarning: Attempted to set non-positive left xlim on a log-scaled axis.
Invalid limit will be ignored.
plt.clf()
@DougBurke yes, I see it with this example.
I also see this with matplotlib 3.3
This appears to be due to matplotlib issue https://github.com/matplotlib/matplotlib/issues/9970 and so is not a problem with Sherpa (at least not directly)