python - Running an external script with matplotlib commands in Ipython -
i run weird problem. way writing code, first write functions on fly in ipython qt console interactively, , tweak them necessary. once satisfied results, move them py file, use functions @ later time.
so, wrote function supposed plot histogram on screen. if first run py script, call function required arguments, error message, @ bottom of post. if copy , paste function code qt console, , hit enter, function works fine after point.
why function work fine after copy paste qt console, not work if directly call after running script %run script.py
magic?
thanks ideas!
here function:
def plotfreqhist(w_hist_list, head, span, m): ''' generates frequency distribution plot ''' if head == 30.: tr_cond = 'normal' else: tr_cond = 'congested' histweights = np.zeros_like(w_hist_list[0]) + 1. / w_hist_list[0].size * 100 bmap = brewer2mpl.get_map('rdylbu', 'diverging', 10) colors = bmap.mpl_colors mpl.rcparams['axes.color_cycle'] = colors fig = plt.figure(figsize=(12,8)) ax = axes() plt.xlim(0.0,1.2) plt.ylim(0.0,6) plt.xlabel('uniform load [kips/ft]') plt.ylabel('frequency [%]') plt.title('frequency distribution\n number of simulations = %i span length = %.0fft traffic condition = %s' %(m, span, tr_cond)) ax.xaxis.set_major_locator(multiplelocator(0.1)) ax.xaxis.set_minor_locator(multiplelocator(0.02)) ax.yaxis.set_major_locator(multiplelocator(1.0)) ax.yaxis.set_minor_locator(multiplelocator(0.2)) plt.grid(b=true, which='major', linewidth=1.0) plt.grid(b=true, which='minor') in xrange(len(w_hist_list)): hist(w_hist_list[i], bins = 200, range = (0,2), normed = 0, cumulative = 0, histtype = charttype, linewidth=2.0, alpha =0.5, weights = histweights) plt.show()
and here error message:
traceback (most recent call last): file "c:\python27\lib\site-packages\ipython\core\ultratb.py", line 779, in structured_traceback records = _fixed_getinnerframes(etb, context, tb_offset) file "c:\python27\lib\site-packages\ipython\core\ultratb.py", line 245, in _fixed_getinnerframes records = fix_frame_records_filenames(inspect.getinnerframes(etb, context)) file "c:\python27\lib\inspect.py", line 1043, in getinnerframes framelist.append((tb.tb_frame,) + getframeinfo(tb, context)) file "c:\python27\lib\inspect.py", line 1007, in getframeinfo lines, lnum = findsource(frame) file "c:\python27\lib\inspect.py", line 580, in findsource if pat.match(lines[lnum]): break indexerror: list index out of range error: internal python error in inspect module. below traceback internal error. unfortunately, original traceback can not constructed.
Comments
Post a Comment