Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list_plot of a nearly constant sequence fails #11973

Closed
dandrake opened this issue Nov 1, 2011 · 12 comments
Closed

list_plot of a nearly constant sequence fails #11973

dandrake opened this issue Nov 1, 2011 · 12 comments

Comments

@dandrake
Copy link
Contributor

dandrake commented Nov 1, 2011

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.)

CC: @novoselt

Component: graphics

Keywords: list_plot, matplotlib, sd40.5

Issue created by migration from https://trac.sagemath.org/ticket/11973

@kcrisman
Copy link
Member

kcrisman commented Nov 1, 2011

comment:1

Here are a whole bunch of (closed) related tickets.

@jasongrout
Copy link
Member

comment:3

This happens with plot too:

plot(lambda x: x*1+(1-x)*(1+1e-13),(x,0,1))

@jasongrout
Copy link
Member

comment:4

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.

@jasongrout
Copy link
Member

comment:5

My test cases are:

sage: list_plot([0,0+1e-14]) # works

sage: list_plot([1,1+1e-14]) # doesn't work

@jasongrout
Copy link
Member

comment:6

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.

@jdemeyer
Copy link

jdemeyer commented Nov 3, 2011

Milestone sage-4.7.3 deleted

@jdemeyer jdemeyer removed this from the sage-4.8 milestone Nov 3, 2011
@sagetrac-dsm
Copy link
Mannequin

sagetrac-dsm mannequin commented May 25, 2012

comment:8

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.

@sagetrac-dsm sagetrac-dsm mannequin added this to the sage-5.1 milestone May 25, 2012
@jasongrout
Copy link
Member

comment:9

Great; if you can post to the matplotlib mailing list and post the thread URL here, that would be great.

@novoselt
Copy link
Member

Changed keywords from list_plot, matplotlib to list_plot, matplotlib, sd40.5

@dandrake
Copy link
Contributor Author

comment:11

I'll contact matplotlib-devel and see what they think of the problem.

@dandrake
Copy link
Contributor Author

comment:12

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.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@fchapoton
Copy link
Contributor

comment:17

everything works in 6.6.rc0

@fchapoton fchapoton removed this from the sage-6.4 milestone Mar 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants