Problems plotting large values in pyroot

Hi,

Im using pyroot to plot some data, and I’m running into a problem when plotting data points with large values. anything larger than 10^40 seems to be plotted as infinite. I’ve written up a simple macro to demonstrate the problem:


from ROOT import TCanvas, TGraph, TMultiGraph, TPad
from ROOT import gROOT
import numpy as np
from array import array

#canvas
c1 = TCanvas('c1','Cross Sections',200,10,700,500)
c1.SetGrid()
c1.SetLogy()
c1.SetLogx()

#x axis
X=array('f',[.5,1,.5e2,1e2,.5e3,1e3,.5e4,1e4,.5e5,1e5,.5e6,1e6,.5e7,1e7,.5e8,1e8,.5e9,1e9,.5e10,1e10])
y=[]
graph=TMultiGraph("lv_test","Large Value Test")

c=2
for n in range(1,7):
        for x in X:
                y.append(x**n)
        Y=array('f',y)
        g=TGraph(20,X,Y)
        g.SetMarkerStyle(20)
        g.SetMarkerColor(c)
        g.SetTitle("y=x^{}".format(str(n)))
        graph.Add(g)
        y=[]
        c+=1
graph.SetMinimum(.01)
graph.SetMaximum(1e60)
graph.Draw("APL")
c1.BuildLegend()
c1.Update()
choice = raw_input("press enter to continue")
c1.SaveAs("lv_test.png")

large_value_test.py (741 Bytes)

when I run it, the points greater then 10^40 are being plotted far to high:

These are very simple functions to plot, so it seems to be a problem in the way the program is handling large numbers. I suspect that the values are being read as infinite as when I run the code without setting the y bounds manually I get this error:

TCanvas::ResizePad:0: RuntimeWarning: Inf/NaN propagated to the pad. Check drawn objects.
TCanvas::ResizePad:0: RuntimeWarning: c1 height changed from 0 to 10

Error in <TCanvas::RangeAxis>: illegal axis coordinates range: xmin=-0.346787, ymin=inf, xmax=10.021189, ymax=inf

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================

Thread 2 (Thread 0x7f91e2bd3700 (LWP 31234)):
#0  0x00007f91f12ce827 in futex_abstimed_wait_cancelable (private=0, abstime=0x0, expected=0, futex_word=0x560f5e7dbcd0) at ../sysdeps/unix/sysv/linux/futex-internal.h:205
#1  do_futex_wait (sem=sem
entry=0x560f5e7dbcd0, abstime=0x0) at sem_waitcommon.c:111
#2  0x00007f91f12ce8d4 in __new_sem_wait_slow (sem=0x560f5e7dbcd0, abstime=0x0) at sem_waitcommon.c:181
#3  0x00007f91f12ce97a in __new_sem_wait (sem=<optimized out>) at sem_wait.c:29
#4  0x00007f91f15eb886 in PyThread_acquire_lock () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#5  0x00007f91f15b5808 in PyEval_RestoreThread () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#6  0x00007f91e2bd615c in time_sleep () from /home/cmwedin/anaconda2/lib/python2.7/lib-dynload/time.so
#7  0x00007f91f15bf039 in PyEval_EvalFrameEx () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#8  0x00007f91f15c05a9 in PyEval_EvalCodeEx () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#9  0x00007f91f1548e77 in function_call () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#10 0x00007f91f1524653 in PyObject_Call () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#11 0x00007f91f15b9002 in PyEval_EvalFrameEx () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#12 0x00007f91f15bfd7a in PyEval_EvalFrameEx () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#13 0x00007f91f15bfd7a in PyEval_EvalFrameEx () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#14 0x00007f91f15c05a9 in PyEval_EvalCodeEx () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#15 0x00007f91f1548d8a in function_call () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#16 0x00007f91f1524653 in PyObject_Call () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#17 0x00007f91f15332fd in instancemethod_call () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#18 0x00007f91f1524653 in PyObject_Call () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#19 0x00007f91f15b5ec8 in PyEval_CallObjectWithKeywords () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#20 0x00007f91f15efd76 in t_bootstrap () from /home/cmwedin/anaconda2/bin/../lib/libpython2.7.so.1.0
#21 0x00007f91f12c66ba in start_thread (arg=0x7f91e2bd3700) at pthread_create.c:333
#22 0x00007f91f08ec41d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 1 (Thread 0x7f91f1ab3700 (LWP 31205)):
#0  0x00007f91f08b10cb in __GI___waitpid (pid=31237, stat_loc=stat_loc
entry=0x7ffc27fd0780, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007f91f0829fbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007f91ef27f76d in TUnixSystem::StackTrace() () from /home/cmwedin/software/root/lib/libCore.so
#3  0x00007f91ef281dac in TUnixSystem::DispatchSignals(ESignals) () from /home/cmwedin/software/root/lib/libCore.so
#4  <signal handler called>
#5  0x00007f91e1a2f097 in FT_Done_Glyph () from /home/cmwedin/software/root/lib/libGraf.so
#6  0x00007f91e1a205c8 in TTF::LayoutGlyphs() () from /home/cmwedin/software/root/lib/libGraf.so
#7  0x00007f91d7d03f01 in TGX11TTF::DrawText(int, int, float, float, char const*, TVirtualX::ETextMode) () from /home/cmwedin/software/root/lib/libGX11TTF.so
#8  0x00007f91e1d8ca60 in TPad::PaintText(double, double, char const*) () from /home/cmwedin/software/root/lib/libGpad.so
#9  0x00007f91e19ec892 in TLatex::Analyse(double, double, TLatex::TextSpec_t, char const*, int) () from /home/cmwedin/software/root/lib/libGraf.so
#10 0x00007f91e19e8735 in TLatex::Analyse(double, double, TLatex::TextSpec_t, char const*, int) () from /home/cmwedin/software/root/lib/libGraf.so
#11 0x00007f91e19f04bc in TLatex::PaintLatex1(double, double, double, double, char const*) () from /home/cmwedin/software/root/lib/libGraf.so
#12 0x00007f91e19f122b in TLatex::PaintLatex(double, double, double, double, char const*) () from /home/cmwedin/software/root/lib/libGraf.so
#13 0x00007f91e19dbc14 in TGaxis::PaintAxis(double, double, double, double, double&, double&, int&, char const*, double, bool) () from /home/cmwedin/software/root/lib/libGraf.so
#14 0x00007f91d33d6179 in THistPainter::PaintAxis(bool) () from /home/cmwedin/software/root/lib/libHistPainter.so
#15 0x00007f91d33cbde5 in THistPainter::Paint(char const*) () from /home/cmwedin/software/root/lib/libHistPainter.so
#16 0x00007f91e1637a0d in TMultiGraph::Paint(char const*) () from /home/cmwedin/software/root/lib/libHist.so
#17 0x00007f91e1d9e06b in TPad::PaintModified() () from /home/cmwedin/software/root/lib/libGpad.so
#18 0x00007f91e1d624cc in TCanvas::Update() () from /home/cmwedin/software/root/lib/libGpad.so
#19 0x00007f91f19d002a in ?? ()
#20 0x0000000000000000 in ?? ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007f91e1a2f097 in FT_Done_Glyph () from /home/cmwedin/software/root/lib/libGraf.so
#6  0x00007f91e1a205c8 in TTF::LayoutGlyphs() () from /home/cmwedin/software/root/lib/libGraf.so
#7  0x00007f91d7d03f01 in TGX11TTF::DrawText(int, int, float, float, char const*, TVirtualX::ETextMode) () from /home/cmwedin/software/root/lib/libGX11TTF.so
#8  0x00007f91e1d8ca60 in TPad::PaintText(double, double, char const*) () from /home/cmwedin/software/root/lib/libGpad.so
#9  0x00007f91e19ec892 in TLatex::Analyse(double, double, TLatex::TextSpec_t, char const*, int) () from /home/cmwedin/software/root/lib/libGraf.so
#10 0x00007f91e19e8735 in TLatex::Analyse(double, double, TLatex::TextSpec_t, char const*, int) () from /home/cmwedin/software/root/lib/libGraf.so
#11 0x00007f91e19f04bc in TLatex::PaintLatex1(double, double, double, double, char const*) () from /home/cmwedin/software/root/lib/libGraf.so
#12 0x00007f91e19f122b in TLatex::PaintLatex(double, double, double, double, char const*) () from /home/cmwedin/software/root/lib/libGraf.so
#13 0x00007f91e19dbc14 in TGaxis::PaintAxis(double, double, double, double, double&, double&, int&, char const*, double, bool) () from /home/cmwedin/software/root/lib/libGraf.so
#14 0x00007f91d33d6179 in THistPainter::PaintAxis(bool) () from /home/cmwedin/software/root/lib/libHistPainter.so
#15 0x00007f91d33cbde5 in THistPainter::Paint(char const*) () from /home/cmwedin/software/root/lib/libHistPainter.so
#16 0x00007f91e1637a0d in TMultiGraph::Paint(char const*) () from /home/cmwedin/software/root/lib/libHist.so
#17 0x00007f91e1d9e06b in TPad::PaintModified() () from /home/cmwedin/software/root/lib/libGpad.so
#18 0x00007f91e1d624cc in TCanvas::Update() () from /home/cmwedin/software/root/lib/libGpad.so
#19 0x00007f91f19d002a in ?? ()
#20 0x0000000000000000 in ?? ()
===========================================================

large_value_error.txt (7.8 KB)

Has anyone encountered this before?

OS: Ubuntu 16.04
Python version: 2.7.13
Root version: 6.12/04

you should probably test with float64 instead of float32.

here are the numbers I get using float32 (ie with a dtype=="f"):

i= 1
ys=[0.5 1 50 100 500 1000 5000 10000 50000 100000 500000 1e+06 5e+06 1e+07 5e+07 1e+08 5e+08 1e+09 5e+09 1e+10]
i= 2
ys=[0.25 1 2500 10000 250000 1e+06 2.5e+07 1e+08 2.5e+09 1e+10 2.5e+11 1e+12 2.5e+13 1e+14 2.5e+15 1e+16 2.5e+17 1e+18 2.5e+19 1e+20]
i= 3
ys=[0.125 1 125000 1e+06 1.25e+08 1e+09 1.25e+11 1e+12 1.25e+14 1e+15 1.25e+17 1e+18 1.25e+20 1e+21 1.25e+23 1e+24 1.25e+26 1e+27 1.25e+29 1e+30]
i= 4
ys=[0.0625 1 6.25e+06 1e+08 6.25e+10 1e+12 6.25e+14 1e+16 6.25e+18 1e+20 6.25e+22 1e+24 6.25e+26 1e+28 6.25e+30 1e+32 6.25e+34 1e+36 +Inf +Inf]
i= 5
ys=[0.03125 1 3.125e+08 1e+10 3.125e+13 1e+15 3.125e+18 1e+20 3.125e+23 1e+25 3.125e+28 1e+30 3.125e+33 1e+35 3.125e+38 +Inf +Inf +Inf +Inf +Inf]
i= 6
ys=[0.015625 1 1.5625e+10 1e+12 1.5625e+16 1e+18 1.5625e+22 1e+24 1.5625e+28 1e+30 1.5625e+34 1e+36 +Inf +Inf +Inf +Inf +Inf +Inf +Inf +Inf]
i= 7
ys=[0.0078125 1 7.8125e+11 1e+14 7.8125e+18 1e+21 7.8125e+25 1e+28 7.8125e+32 1e+35 +Inf +Inf +Inf +Inf +Inf +Inf +Inf +Inf +Inf +Inf]

and here are the ones with float64:

i= 1
ys=[0.5 1 50 100 500 1000 5000 10000 50000 100000 500000 1e+06 5e+06 1e+07 5e+07 1e+08 5e+08 1e+09 5e+09 1e+10]
i= 2
ys=[0.25 1 2500 10000 250000 1e+06 2.5e+07 1e+08 2.5e+09 1e+10 2.5e+11 1e+12 2.5e+13 1e+14 2.5e+15 1e+16 2.5e+17 1e+18 2.5e+19 1e+20]
i= 3
ys=[0.125 1 125000 1e+06 1.25e+08 1e+09 1.25e+11 1e+12 1.25e+14 1e+15 1.25e+17 1e+18 1.25e+20 1e+21 1.25e+23 1e+24 1.25e+26 1e+27 1.25e+29 1e+30]
i= 4
ys=[0.0625 1 6.25e+06 1e+08 6.25e+10 1e+12 6.25e+14 1e+16 6.25e+18 1e+20 6.25e+22 1e+24 6.25e+26 1e+28 6.25e+30 1e+32 6.25e+34 1e+36 6.25e+38 1e+40]
i= 5
ys=[0.03125 1 3.125e+08 1e+10 3.125e+13 1e+15 3.125e+18 1e+20 3.125e+23 1e+25 3.125e+28 1e+30 3.125e+33 1e+35 3.125e+38 1e+40 3.1250000000000003e+43 1.0000000000000001e+45 3.125e+48 1e+50]
i= 6
ys=[0.015625 1 1.5625e+10 1e+12 1.5625e+16 1e+18 1.5625e+22 1e+24 1.5625e+28 1e+30 1.5625e+34 1e+36 1.5624999999999998e+40 9.999999999999999e+41 1.5625e+46 1e+48 1.5625e+52 1e+54 1.5625e+58 1e+60]
i= 7
ys=[0.0078125 1 7.8125e+11 1e+14 7.8125e+18 1e+21 7.8125e+25 1e+28 7.8125e+32 1e+35 7.8125e+39 1e+42 7.8125e+46 1e+49 7.8125e+53 1e+56 7.8125e+60 1e+63 7.8125e+67 1e+70]

This was exactly the problem, it seems very obvious in retrospect. Thank you from the suggestion!