fig = plt.figure(figsize=(12, 5)) ax = plt.subplot( 121 ) ax.set_title( 'Plot title (left)' ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'x label' ) ax.set_ylabel( 'y label' ) plt.ticklabel_format(style='sci', axis='y', scilimits=(-2,2), useMathText=True) hist.hist.hist.plot_hist(label='histogram 1') ax.legend() ax = plt.subplot( 122 ) ax.set_title( 'Plot title (right)' ) ax.minorticks_on() ax.grid() ax.set_xlabel( 'x label' ) ax.set_ylabel( 'y label' ) plt.ticklabel_format(style='sci', axis='y', scilimits=(-2,2), useMathText=True) hist.hist.hist.plot_bar(label='histogram 1 (bar)', alpha=0.6) ax.legend() from mpl_tools.helpers import savefig savefig(tutorial_image_name('png')) plt.show()
narray = np.exp(-0.5 * (X - 15.0)**2 / 10.0**2 - 0.5 * (Y - 30.0)**2 / 3.0**2) # Create a histogram instance with data, stored in `narray` # and edges, stored in `edges` hist = C.Histogram2d(edgesx, edgesy, narray) fig = plt.figure() ax = plt.subplot(111) ax.set_title('pcolorfast') ax.minorticks_on() ax.set_xlabel('x label') ax.set_ylabel('y label') hist.hist.hist.plot_pcolorfast(colorbar=True) savefig(tutorial_image_name('png', suffix='pcolorfast')) fig = plt.figure() ax = plt.subplot(111) ax.set_title('imshow') ax.minorticks_on() ax.set_xlabel('x label') ax.set_ylabel('y label') hist.hist.hist.plot_imshow(colorbar=True) savefig(tutorial_image_name('png', suffix='imshow')) fig = plt.figure() ax = plt.subplot(111) ax.set_title('matshow')
narray = np.exp(-0.5 * (X - cx[15])**2 / 150.0**2 - 0.5 * (Y - cy[20])**2 / 0.10**2) # Create a histogram instance with data, stored in `narray` # and edges, stored in `edges` hist = C.Histogram2d(edgesx, edgesy, narray) fig = plt.figure() ax = plt.subplot(111) ax.set_title('pcolormesh') ax.minorticks_on() ax.set_xlabel('x label') ax.set_ylabel('y label') hist.hist.hist.plot_pcolormesh(colorbar=True) savefig(tutorial_image_name('png', suffix='pcolormesh')) fig = plt.figure() ax = plt.subplot(111) ax.set_title('pcolor') ax.minorticks_on() ax.set_xlabel('x label') ax.set_ylabel('y label') hist.hist.hist.plot_pcolor(colorbar=True) savefig(tutorial_image_name('png', suffix='pcolor')) plt.show()
alpha=0.4, linewidth=0.5) ax.legend(loc='lower right') # Add difference ax = plt.subplot(gs[3, 0], sharex=ax) ax.set_xlabel('x') diff_factor = 1.e-7 ax.set_ylabel(r'diff., $\times10^{-7}$') diff = integral_n - integral_a ax.bar(x_edges[:-1], diff / diff_factor, bar_width * 2.0, align='edge') # Freeze axis limits and draw bin edges ax.autoscale(enable=True, axis='y') ymin, ymax = ax.get_ylim() ax.vlines(integrator.points.xedges.data(), ymin, ymax, linestyle='--', alpha=0.4, linewidth=0.5) # Save figure and graph as images savefig(tutorial_image_name('png')) savegraph(fcn.sum, tutorial_image_name('png', suffix='graph'), rankdir='TB') plt.show()
hist1 = C.Histogram(edges, data1) hist1.hist.setLabel('Input histogram 1') hist2 = C.Histogram(edges, data2) hist2.hist.setLabel('Input histogram 2') hist3 = C.Histogram(edges, data3) hist3.hist.setLabel('Input histogram 3') # # Bind outputs # suffix = '' if cfg.split_transformations else 'merged_' savegraph(b.context.outputs.smearing_matrix.values(), tutorial_image_name('png', suffix=suffix + 'graph0'), rankdir='TB') hist1 >> b.context.inputs.smearing_matrix.values(nested=True) hist1 >> b.context.inputs.eres.D1.values(nested=True) hist2 >> b.context.inputs.eres.D2.values(nested=True) hist3 >> b.context.inputs.eres.D3.values(nested=True) print(b.context) savegraph(hist1, tutorial_image_name('png', suffix=suffix + 'graph1'), rankdir='TB') # # Plot #
print(' <no functions executed>') print() print('Done') integrator.print() print() print(dbg1b.debug.target.data().sum(), dbg2b.debug.target.data().sum()) # # Label transformations hist.hist.setLabel('Input histogram\n(bins definition)') integrator.points.setLabel('Sampler\n(Gauss-Legendre)') sin_t.sin.setLabel('sin(x)') cos1_arg.sum.setLabel('k1*x') cos2_arg.sum.setLabel('k2*x') cos1_t.cos.setLabel('cos(k1*x)') cos2_t.cos.setLabel('cos(k2*x)') int1.setLabel('Integrator 1\n(convolution)') int2.setLabel('Integrator 2\n(convolution)') fcn1.sum.setLabel('a1*sin(x) + b1*cos(k1*x)') fcn2.sum.setLabel('a2*sin(x) + b2*cos(k2*x)') dbg1a.debug.setLabel('Debug 1\n(before integral 1)') dbg2a.debug.setLabel('Debug 2\n(before integral 2)') dbg1b.debug.setLabel('Debug 1\n(after integral 1)') dbg2b.debug.setLabel('Debug 2\n(after integral 2)') savegraph(int_points, tutorial_image_name('png', suffix='graph'), rankdir='TB') plt.show()
# Create a histogram instance with data, stored in `narray` # and edges, stored in `edges` hist = C.Histogram2d(edgesx, edgesy, narray) from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = plt.subplot(111, projection='3d') ax.set_title('surface') ax.minorticks_on() ax.set_xlabel('x label') ax.set_ylabel('y label') hist.hist.hist.plot_surface(cmap='viridis', colorbar=True) savefig(tutorial_image_name('png', suffix='surface')) fig = plt.figure() ax = plt.subplot(111, projection='3d') ax.set_title('bar3d') ax.minorticks_on() ax.set_xlabel('x label') ax.set_ylabel('y label') hist.hist.hist.plot_bar3d(cmap=True, colorbar=True) savefig(tutorial_image_name('png', suffix='bar3d')) fig = plt.figure() ax = plt.subplot(111, projection='3d') ax.set_title('wireframe')
fig = plt.figure() ax = plt.subplot(111) ax.minorticks_on() ax.grid() ax.set_xlabel('X axis') ax.set_ylabel('Entries') ax.set_title('Points and TH1 comparison') roothist1d.plot(alpha=0.6, linestyle='dashdot', label='TH1') h1d.hist.hist.plot_hist(alpha=0.6, linestyle='dashed', label='Histogram') p1.points.points.plot_hist(label='Points') ax.legend(loc='upper center', ncol=3) ax.set_ylim(top=ax.get_ylim()[1] * 1.1) savefig(tutorial_image_name('png', suffix='1d')) # Check p2 fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2, figsize=(8, 8), gridspec_kw=dict(hspace=0.3, wspace=0.35, left=0.10, right=0.90)) ax1.minorticks_on() ax1.grid() ax1.set_xlabel('X axis') ax1.set_ylabel('Y axis') ax1.set_title('TH2')
integrator.points.setLabel('Sampler\n(Gauss-Legendre)') integrator.hist.setLabel('Integrator\n(convolution)') sin_t.sin.setLabel('sin(ax+by)') arg_t.sum.setLabel('ax+by') # Make 2d color plot fig = plt.figure() ax = plt.subplot(111, xlabel='x', ylabel='y', title=r'$\int\int\sin(ax+by)$') ax.minorticks_on() ax.set_aspect('equal') # Draw the function and integrals integrator.hist.hist.plot_pcolormesh(colorbar=True) # Save figure savefig(tutorial_image_name('png')) # Add integration points and save ax.scatter(X, Y, c='red', marker='.', s=0.2) ax.set_xlim(-0.5, 0.5) ax.set_ylim(0.0, 1.0) savefig(tutorial_image_name('png', suffix='zoom')) # Plot 3d function and a histogram fig = plt.figure() ax = plt.subplot(111, xlabel='x', ylabel='y', title=r'$\sin(ax+by)$', projection='3d')
for i, p in enumerate(points_list): p.points.setLabel('Sum input:\nP{:d}'.format(i)) tfactor.points.setLabel('Scale S') tsum.sum.setLabel('Sum of matrices') tprod.product.setLabel('Scaled matrix') tprod.product.product.setLabel('result') tsum.print() print() tprod.print() print() print('The sum:') print(tsum.transformations[0].outputs[0].data()) print() print('The scale:') print(tfactor.transformations[0].outputs[0].data()) print() print('The scaled sum:') print(tprod.transformations[0].outputs[0].data()) print() from gna.graphviz import savegraph savegraph(tprod.transformations[0], tutorial_image_name('dot'), rankdir='TB') savegraph(tprod.transformations[0], tutorial_image_name('pdf'), rankdir='TB') savegraph(tprod.transformations[0], tutorial_image_name('png'), rankdir='TB')
ax.set_title('Plot title (left)') ax.minorticks_on() ax.grid() ax.set_xlabel('x label') ax.set_ylabel('y label') plt.ticklabel_format(style='sci', axis='y', scilimits=(-2, 2), useMathText=True) hist1.hist.hist.plot_hist(label='exp(+)') hist2.hist.hist.plot_hist(label='exp(-)') hist3.hist.hist.plot_hist(label='gauss') ax.legend() savefig(tutorial_image_name('png', suffix='hist')) fig = plt.figure() ax = plt.subplot(111) ax.set_title('Plot title (left)') ax.minorticks_on() ax.grid() ax.set_xlabel('x label') ax.set_ylabel('y label') plt.ticklabel_format(style='sci', axis='y', scilimits=(-2, 2), useMathText=True) hist1.hist.hist.plot_bar(label='exp(+)', alpha=0.4) hist2.hist.hist.plot_bar(label='exp(-)', alpha=0.4)