Opened 10 years ago
Closed 7 years ago
#11973 closed defect (fixed)
list_plot of a nearly constant sequence fails
Reported by: | ddrake | Owned by: | jason, was |
---|---|---|---|
Priority: | minor | Milestone: | sage-duplicate/invalid/wontfix |
Component: | graphics | Keywords: | list_plot, matplotlib, sd40.5 |
Cc: | novoselt | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
At https://groups.google.com/d/topic/sage-devel/gu0Al01k-3Y/discussion I noted that list_plot/matplotlib are confused when given a nearly-constant sequence:
sage: list_plot([[0, 0.7886751345948214], [0.01, 0.788675134595], [0.02, 0.788675134595], [0.03, 0.788675134595], [0.04, 0.788675134595], [0.05, 0.788675134595], [0.06, 0.788675134595], [0.07, 0.788675134595], [0.08, 0.788675134595], [0.09, 0.788675134595], [0.1, 0.788675134595]])
fails with
... /opt/sage/local/lib/python2.6/site-packages/matplotlib/axis.pyc in get_minorticklabels(self) 1076 def get_minorticklabels(self): 1077 'Return a list of Text instances for the minor ticklabels' -> 1078 ticks = self.get_minor_ticks() 1079 labels1 = [tick.label1 for tick in ticks if tick.label1On] 1080 labels2 = [tick.label2 for tick in ticks if tick.label2On] /opt/sage/local/lib/python2.6/site-packages/matplotlib/axis.pyc in get_minor_ticks(self, numticks) 1190 'get the minor tick instances; grow as necessary' 1191 if numticks is None: -> 1192 numticks = len(self.get_minor_locator()()) 1193 1194 if len(self.minorTicks) < numticks: /opt/sage/local/lib/python2.6/site-packages/matplotlib/ticker.pyc in __call__(self) 1424 1425 # don't create minor ticks on top of existing major ticks -> 1426 diff = 0.5 * abs(locs[1] - locs[0]) 1427 locs = [l for l in locs if (np.abs(l - majorlocs) > diff).all()] 1428 IndexError: index out of bounds
(with 4.7.1 on 64-bit Linux.)
Since the usual plot() function works with constant functions, there should be a way to get this working. (Or, we should decide that this is a matplotlib bug and properly report it.)
Change History (19)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
- Cc novoselt added
comment:3 Changed 10 years ago by
This happens with plot too:
plot(lambda x: x*1+(1-x)*(1+1e-13),(x,0,1))
comment:4 Changed 10 years ago by
It appears that the major locator is giving back bad values (i.e., somehow it is giving back [0,1,2] as the major tickmarks, which is then trimmed down to just 1, giving the minor locator error since there is only one major tickmark).
I think the problem is somewhere in matplotlib.ticker.MaxNLocator.bin_boundaries function, but I'm not sure.
comment:5 Changed 10 years ago by
My test cases are:
sage: list_plot([0,0+1e-14]) # works sage: list_plot([1,1+1e-14]) # doesn't work
comment:6 Changed 10 years ago by
I think the next step would be to try to replicate it using only matplotlib. If we can do that, we can move the bug report upstream.
comment:8 Changed 10 years ago by
- Milestone set to sage-5.1
I think we can bump this up:
import pylab pylab.plot([0, 1], [0, 1e-14]) pylab.savefig("works.png") pylab.close() pylab.plot([0, 1], [1, 1+1e-14]) pylab.savefig("fails.png") pylab.close()
reproduces the problem in mpl 1.2.x.
comment:9 Changed 10 years ago by
Great; if you can post to the matplotlib mailing list and post the thread URL here, that would be great.
comment:10 Changed 10 years ago by
- Keywords sd40.5 added
comment:11 Changed 10 years ago by
I'll contact matplotlib-devel and see what they think of the problem.
comment:12 Changed 10 years ago by
Interesting: the example I gave in the description works in 5.1beta0 (64-bit Linux), but the y-axis doesn't have any labels. The plot is correct for the given data, though.
comment:13 Changed 8 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:14 Changed 8 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:15 Changed 8 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:16 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:17 Changed 7 years ago by
- Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
- Status changed from new to needs_review
everything works in 6.6.rc0
comment:18 Changed 7 years ago by
- Status changed from needs_review to positive_review
comment:19 Changed 7 years ago by
- Resolution set to fixed
- Status changed from positive_review to closed
Here are a whole bunch of (closed) related tickets.
I suspect the last one has some clues, but I can't remember off-hand which of these actually fixed that before. Note that the error message here is different, because it's now an mpl error.