def show_fit (order, N, q, f, query, cooks_threshold, **stats): p = gp.gnuplotlib(equation='{} with lines title "reference"'.format(reference_equation), xrange=[-1,2], title = "Fit with order={} Npoints={} stdev={}".format(order, N, noise_stdev)) p.plot((q, f, dict(legend = 'input data', _with='points')), (query, stats['fquery'] + np.sqrt(stats['Vquery'])*np.array(((1,),(0,),(-1,),)), dict(legend = 'stdev_f', _with='lines'))) return p
def show_uncertainty(order, N, q, f, query, cooks_threshold, **stats): coeffs = stats['p'] fitted_equation = '+'.join(['{} * x**{}'.format(coeffs[i], i) for i in range(len(coeffs))]) p = gp.gnuplotlib(equation='({})-({}) title "Fit error off ground truth; y2 axis +- noise stdev" axis x1y2'.format(reference_equation,fitted_equation), title = "Uncertainty with order={} Npoints={} stdev={}".format(order, N, noise_stdev), ymin=0, y2range = (-noise_stdev, noise_stdev), _set = 'y2tics' ) # p.plot( # (query, np.sqrt(stats['Vquery]), # dict(legend='expectederr (y2)', _with='lines', y2=1)), # (query, stats['metrics']['dima']['query']['self_others']*noise_stdev*noise_stdev / stats['dimas_threshold'], # dict(legend="Dima's self+others query / threshold", # _with='linespoints')), # (query, stats['metrics']['dima']['query']['others']*noise_stdev*noise_stdev / stats['dimas_threshold'], # dict(legend="Dima's others-ONLY query / threshold", # _with='linespoints')), # (query, stats['metrics']['cook']['query']['self_others']*noise_stdev*noise_stdev / cooks_threshold, # dict(legend="Cook's self+others query / threshold", # _with='linespoints')), # (query, stats['metrics']['cook']['query']['others']*noise_stdev*noise_stdev / cooks_threshold, # dict(legend="Cook's others-ONLY query / threshold", # _with='linespoints'))) p.plot( # (query, np.sqrt(Vquery), # dict(legend='Expected error due to input noise (y2)', _with='lines', y2=1)), (query, np.sqrt(stats['metrics']['dima']['query']['self'])*noise_stdev, dict(legend="Dima's self-ONLY; 1 point", _with='linespoints')), (query, np.sqrt(stats['metrics']['dima']['query']['others'])*noise_stdev, dict(legend="Dima's others-ONLY ALL {} points".format(Nquery), _with='linespoints')), # (query, np.sqrt(stats['metrics']['dima']['query']['others'])*noise_stdev * Nquery, # dict(legend="Dima's others-ONLY 1 point average", # _with='linespoints')), ) return p
def show_outlierness(order, N, q, f, query, cooks_threshold, **stats): p = gp.gnuplotlib(equation='1.0 title "Threshold"', title = "Outlierness with order={} Npoints={} stdev={}".format(order, N, noise_stdev)) p.plot( (q, stats['metrics']['dima']['outliers']['self_others']/stats['dimas_threshold'], dict(legend="Dima's self+others outlierness / threshold", _with='points')), (q, stats['metrics']['dima']['outliers']['others']/stats['dimas_threshold'], dict(legend="Dima's others-ONLY outlierness / threshold", _with='points')), (q, stats['metrics']['cook']['outliers']['self_others']/cooks_threshold, dict(legend="Cook's self+others outlierness / threshold", _with='points')), (q, stats['metrics']['cook']['outliers']['others']/cooks_threshold, dict(legend="Cook's others-ONLY outlierness / threshold", _with='points'))) return p
import smoldyn import math import numpy as np try: import moose import rdesigneur as rd import gnuplotlib as gp except Exception: print('[WARN] MOOSE/gnuplotlib are missing. To install' ' $ python3 -m pip install pymoose --pre --user ' ' $ python3 -m pip install gnuplotlib') quit(0) g1_ = gp.gnuplotlib(title="MOOSE simualtion: Soma") ####################################### # MOOSE model # A chemical oscillator. ###################################### rdes = rd.rdesigneur( chanProto=[["make_HH_Na()", "Na"], ["make_HH_K()", "K"]], chanDistrib=[["Na", "soma", "Gbar", "1200"], ["K", "soma", "Gbar", "360"]], stimList=[["soma", "1", ".", "inject", "((t%0.2)>0.1)*1e-8"]], plotList=[["soma", "1", ".", "Vm", "Membrane potential"]], ) rdes.buildModel() moose.reinit() mooseT_, mooseY_ = [], [] elem_ = moose.element("/model/elec/soma[0]")
import numpy as np import gnuplotlib as gp x = np.arange(101) - 50 gp.plot(x**2) #[ basic parabola plot pops up ] g1 = gp.gnuplotlib(title='Parabola with error bars', _with='xyerrorbars') g1.plot(x**2 * 10, np.abs(x) / 10, np.abs(x) * 5, legend='Parabola', tuplesize=4) #[ parabola with x,y errobars pops up in a new window ] x, y = np.ogrid[-10:11, -10:11] gp.plot(x**2 + y**2, title='Heat map', unset='grid', cmds='set view map', _with='image', tuplesize=3) #[ Heat map pops up where first parabola used to be ] theta = np.linspace(0, 6 * np.pi, 200) z = np.linspace(0, 5, 200) g2 = gp.gnuplotlib(_3d=True) g2.plot(np.cos(theta), np.vstack((np.sin(theta), -np.sin(theta))), z) #[ Two 3D spirals together in a new window ] x = np.arange(1000)
istate0_frames = mrcal.state_index_frames(0, **baseline) istate0_calobject_warp = mrcal.state_index_calobject_warp(**baseline) istate0_extrinsics = mrcal.state_index_extrinsics(0, **baseline) if istate0_extrinsics is None: istate0_extrinsics = istate0_frames slice_intrinsics = slice(0, istate0_extrinsics) slice_extrinsics = slice(istate0_extrinsics, istate0_frames) slice_frames = slice(istate0_frames, istate0_calobject_warp) # These thresholds look terrible. And they are. But I'm pretty sure this is # working properly. Look at the plots: if 0: import gnuplotlib as gp plot_dp = gp.gnuplotlib( title="dp predicted,observed", _set=mrcal.plotoptions_state_boundaries(**optimization_inputs)) plot_dp.plot( (nps.cat(dp_observed, dp_predicted), dict(legend=np.array( ('observed', 'predicted')), _with='linespoints')), (dp_observed - dp_predicted, dict(legend="err", _with="lines lw 2", y2=1))) plot_dp.wait() testutils.confirm_equal(dp_predicted[slice_intrinsics], dp_observed[slice_intrinsics], percentile=80, eps=0.2, msg=f"Predicted dp from dqref: intrinsics") testutils.confirm_equal(dp_predicted[slice_extrinsics],
time.sleep(sleep_interval) gp.plot((x**2)) time.sleep(sleep_interval) gp.plot((-x, x**3, {'with': 'lines'}), (x**2,)) time.sleep(sleep_interval) gp.plot( x, np.vstack((x**3, x**2)) ) time.sleep(sleep_interval) gp.plot( np.vstack((-x**3, x**2)), _with='lines' ) time.sleep(sleep_interval) gp.plot( (np.vstack((x**3, -x**2)), {'with': 'points'} )) time.sleep(sleep_interval) ################################# # some more varied plotting, using the object-oriented interface plot1 = gp.gnuplotlib(_with = 'linespoints', xmin = -10, title = 'Error bars and other things') plot1.plot( ( np.vstack((x, x*2, x*3)), x**2 - 300, {'with': 'lines lw 4', 'y2': True, 'legend': 'parabolas'}), (x**2 * 10, x**2/40, x**2/2, # implicit domain {'with': 'xyerrorbars', 'tuplesize': 4}), (x, np.vstack((x**3, x**3 - 100)), {"with": 'lines', 'legend': 'shifted cubics', 'tuplesize': 2}))
if x == 0: print(Fore.GREEN, x, " ", end="") elif abs(x) == 1: print(Fore.YELLOW, x, " ", end="") else: print(Fore.RED, x, " ", end="") if x in stats: stats[x] += 1 else: stats[x] = 1 dbl.append(x) print(Style.RESET_ALL) print("STATS: ", stats) if found: g1 = gp.gnuplotlib(title='Baseline difference statistics', terminal='dumb 100,40') xx = np.arange(-31, 32, 1) yy = np.array([stats[x] if x in stats else 0 for x in xx]) g1.plot((xx, yy, {'with': 'impulses'}), _with='lines', unset="grid") # z = np.arange(1000) # g1.plot((np.array(dbl), dict(histogram = 'freq', binwidth=1)), unset='grid')
), ), dict(_with='labels', tuplesize=3)), _set='yrange [5:10]', unset='grid', wait=True) # # This should make no plot at all, with a warning that all the data is out of # # bounds. I haven't written a test harness to look at stderr output yet, so I # # disable this check # gp.plot( np.arange(10), # _set = 'xrange [10:20]', # wait = True) ################################# # some more varied plotting, using the object-oriented interface plot1 = gp.gnuplotlib(_with='linespoints', xmin=-10, title='Error bars and other things', wait=1) plot1.plot( (nps.cat(x, x * 2, x * 3), x**2 - 300, dict(_with='lines lw 4', y2=True, legend='parabolas')), ( x**2 * 10, x**2 / 40, x**2 / 2, # implicit domain dict(_with='xyerrorbars', tuplesize=4)), (x, nps.cat(x**3, x**3 - 100), dict(_with='lines', legend='shifted cubics', tuplesize=2))) #################################
import gnuplotlib as gn import numpy as np in_file = open("function.txt", "r") func = in_file.readline() lst = func.split(" ") a = lst[0] b = lst[1] c = lst[2] x = np.arange(50) g1 = gn.gnuplotlib(title="Quadratic fitting", _with="line") g1.plot(a * x**2, b * x, c, legend="Parabola")
**kwargs) gp.add_plot_option(plot_options, 'set', ('xtics 1', 'ytics 1')) return data_tuples, plot_options if args.show_distribution: plot_distribution = [None] * args.Ncameras for icam in range(args.Ncameras): data_tuples, plot_options = make_plot(icam) if args.extra_observation_at is not None: plot_options['title'] += f': extra at {args.extra_observation_at}' plot_distribution[icam] = gp.gnuplotlib(**plot_options) plot_distribution[icam].plot(*data_tuples) if args.make_documentation_plots is not None: data_tuples_plot_options = \ [ make_plot(icam, report_center_points=False) \ for icam in range(args.Ncameras) ] plot_options = data_tuples_plot_options[0][1] del plot_options['title'] gp.add_plot_option(plot_options, 'unset', 'key') data_tuples = [ data_tuples_plot_options[icam][0] for icam in range(args.Ncameras) ] if args.make_documentation_plots: for extension in ('pdf', 'svg', 'png', 'gp'):
q = x - i try: return sample_segment_cubic(q, *cp[i - 1:i + 3]) except: return 0 y = sample_cubic(x, c) c2 = c.copy() c2[int(N // 2)] *= 1.1 y2 = sample_cubic(x, c2) if not skip_plots: plot1 = gp.gnuplotlib( title='Cubic splines: response to control point perturbation', # hardcopy = '/tmp/cubic-spline-perturbations.svg', # terminal = 'svg size 800,600 noenhanced solid dynamic font ",12"' ) plot1.plot( (x, nps.cat(y, y2), dict(_with=np.array(('lines lc "blue"', 'lines lc "sea-green"')), legend=np.array( ('Spline: baseline', 'Spline: tweaked one control point')))), (t[:len(c)], nps.cat(c, c2), dict(_with=np.array(('points pt 1 ps 1 lc "blue"', 'points pt 2 ps 1 lc "sea-green"')), legend=np.array(('Control points: baseline', 'Control points: tweaked one control point')))), (x, y - y2, dict(_with='lines lc "red"', legend='Difference', y2=1)), _xrange=(10.5, 19.5), y2max=0.01,