What could cause a plot fail in my code?
Peter Pearson
pkpearson at nowhere.invalid
Mon Dec 21 12:54:41 EST 2015
On Mon, 21 Dec 2015 09:29:24 -0800 (PST), Robert <rxjwg98 at gmail.com> wrote:
> On Monday, December 21, 2015 at 12:15:54 PM UTC-5, Robert wrote:
>> Hi,
>>
>> I find a useful code snippet on link:
>>
>> http://stackoverflow.com/questions/25126444/logistic-regression-in-pymc/34400966#34400966
>>
>> but it has error on plot function. The error message is as following:
>> ---------
>> %run "C:\Users\rj\pyprj\logic_regression0.py"
>> [-----------------100%-----------------] 10000 of 10000 complete in 12.6 secPlotting beta0
>> Plotting tau
>> Plotting betaSalad
>> Plotting sigma
>> ---------------------------------------------------------------------------
>> UnboundLocalError Traceback (most recent call last)
>> C:\Users\pyprj\logic_regression0.py in <module>()
>> 34 #m.sample(100000, 50000, 50)
>> 35 m.sample(10000, 5000, 50)
>> ---> 36 pm.Matplot.plot(m)
>> 37 import matplotlib.pyplot as plt
>> 38 #plt.plot(m)
>>
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site- packages\pymc\Matplot.pyc in wrapper(pymc_obj, *args, **kwargs)
>> 339 if args:
>> 340 name = '%s_%s' % (args[0], variable.__name__)
>> --> 341 f(data, name, *args, **kwargs)
>> 342 return
>> 343 except AttributeError:
>>
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc in plot(data, name, format, suffix, path, common_scale, datarange, new, last, rows, num, fontmap, verbose)
>> 453 num=num * 2,
>> 454 last=last,
>> --> 455 fontmap=fontmap)
>> 456
>> 457 if last:
>>
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc in wrapper(pymc_obj, *args, **kwargs)
>> 375
>> 376 # If others fail, assume that raw data is passed
>> --> 377 f(pymc_obj, *args, **kwargs)
>> 378
>> 379 wrapper.__doc__ = f.__doc__
>>
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\pymc\Matplot.pyc in histogram(data, name, bins, datarange, format, suffix, path, rows, columns, num, last, fontmap, verbose)
>> 576
>> 577 # Generate histogram
>> --> 578 hist(data.tolist(), bins, histtype='stepfilled')
>> 579
>> 580 xlim(datarange)
>>
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\pyplot.py in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
>> 2956 histtype=histtype, align=align, orientation=orientation,
>> 2957 rwidth=rwidth, log=log, color=color, label=label,
>> -> 2958 stacked=stacked, data=data, **kwargs)
>> 2959 finally:
>> 2960 ax.hold(washold)
>>
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
>> 1809 warnings.warn(msg % (label_namer, func.__name__),
>> 1810 RuntimeWarning, stacklevel=2)
>> -> 1811 return func(ax, *args, **kwargs)
>> 1812 pre_doc = inner.__doc__
>> 1813 if pre_doc is None:
>>
>> C:\Users\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes\_axes.py in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
>> 6192 ymin = np.amin(m[m != 0])
>> 6193 # filter out the 0 height bins
>> -> 6194 ymin = max(ymin*0.9, minimum) if not input_empty else minimum
>> 6195 ymin = min(ymin0, ymin)
>> 6196 self.dataLim.intervaly = (ymin, ymax)
>>
>> UnboundLocalError: local variable 'ymin' referenced before assignment
>> /////////////
>>
>> I have no clue at all on debug it. Could you help me?
>> Thanks,
>
> Excuse me. The code link should be this one:
>
> http://nbviewer.ipython.org/gist/aflaxman/8329ec1b9f861469f896
>
> Do you experience such errors?
>From a quick look, it appears that you are trying to plot a histogram
in which all the bins are empty.
--
To email me, substitute nowhere->runbox, invalid->com.
More information about the Python-list
mailing list