list_plot / matplotlib can't plot a horizontal line

213 views
Skip to first unread message

Dan Drake

unread,
Oct 31, 2011, 9:56:05 PM10/31/11
to sage-...@googlegroups.com
This doesn't work:

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

The y-values are (almost) all the same, but matplotlib gets stuck trying
to decide on the ticks:

/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

It seems like list_plot should return something in this case. What
matplotlib magic do we need to get some kind of plot? If I plot a
constant function with plot(), it works fine.

Ideas?

Dan

--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------

signature.asc

Jason Grout

unread,
Oct 31, 2011, 10:39:15 PM10/31/11
to sage-...@googlegroups.com

Add a ymin and ymax as a workaround:

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]],ymin=0,ymax=1)

I agree that we should detect this problem when we draw a graphic with
ybounds too close to each other and turn off minor ticks or increase the
ybounds or something. Or maybe it's a bug in matplotlib we should track
down. If we offload it to the matplotlib guys, we should get a purely
matplotlib example of the problem first.

Thanks,

Jason


Dan Drake

unread,
Nov 1, 2011, 3:30:22 AM11/1/11
to sage-...@googlegroups.com
On Mon, 31 Oct 2011 at 09:39PM -0500, Jason Grout wrote:
> Add a ymin and ymax as a workaround:
>
> 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]],ymin=0,ymax=1)
>
> I agree that we should detect this problem when we draw a graphic
> with ybounds too close to each other and turn off minor ticks or
> increase the ybounds or something. Or maybe it's a bug in
> matplotlib we should track down. If we offload it to the matplotlib
> guys, we should get a purely matplotlib example of the problem
> first.

Since plot(constant, ...) works, there's *something* in Sage or
matplotlib that detects and works around this problem. So we just need
to replicate that in list_plot(). (Sadly, that "we" cannot be me; too
busy at the moment.)

This is now ticket #11973: http://trac.sagemath.org/sage_trac/ticket/11973

signature.asc
Reply all
Reply to author
Forward
0 new messages