src/sage/plot/plot.py: random doctest failure
tornaria opened this issue · 3 comments
sage -t --long --random-seed=314121851792717929490963296099377352180 src/sage/plot/plot.py
**********************************************************************
File "src/sage/plot/plot.py", line 1782, in sage.plot.plot.plot
Failed example:
plot(f, (x, -3.5, 3.5), detect_poles='show', exclude=[-3..3], ymin=-5, ymax=5)
Expected:
Graphics object consisting of 12 graphics primitives
Got:
Graphics object consisting of 13 graphics primitives
**********************************************************************
1 item had failures:
1 of 154 in sage.plot.plot.plot
[461 tests, 1 failure, 60.91 s]
----------------------------------------------------------------------
sage -t --long --random-seed=314121851792717929490963296099377352180 src/sage/plot/plot.py # 1 doctest failed
----------------------------------------------------------------------
Looks similar to #29954.
Component: doctest framework
Issue created by migration from https://trac.sagemath.org/ticket/33129
The problem seems to be that the plot routine occasionally decides there is a pole at x = 0, so it fills the gap in the graph with a vertical dashed gray line. This is hard to see because the extra line is on top of the y-axis. To see the effect more easily, you can run the following code:
while True:
f(x) = (floor(x)+0.5) / (1-(x-0.5)^2)
P = plot(f(x - 1), (x, -2.5, 4.5), detect_poles='show',
exclude=[-2..4], ymin=-5, ymax=5)
if "13" in str(P):
bad_plot = P
break
show(bad_plot)
If your experience is the same as mine, the graph will include a vertical dashed line from (1, -2/3) to (1, 2/3). (I didn't do any statistics, but the bad plot seems to happen once every few hundred tries.)
So this doesn't seem to be the same problem as #29954. Instead, it seems we need to make detect_poles smarter.
bump to 9.6
Replying to @DaveWitteMorris:
Instead, it seems we need to make
detect_polessmarter.
I agree. The routine for detecting poles computes the slope between consecutive plot points. In this example, the slope at the discontinuity is just very close to the threshold value, so sometimes a pole is detected there (I am a bit surprised this is not deterministic).
A simple attempt would be to increase the threshold a bit. Also, the detection determines the slope only in absolute terms, not relatively – probably it would be good to consider the y-range as well. For example, scaling your example by 10 always replicates the problem:
sage: f(x) = (floor(x)+0.5) / (1-(x-0.5)^2)
sage: plot(10*f(x - 1), (x, -2.5, 4.5), detect_poles='show', exclude=[-2..4], ymin=-50, ymax=50)
Launched png viewer for Graphics object consisting of 13 graphics primitives