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()
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()
# 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')
# 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) ax.legend(loc='lower right') ymin, ymax = ax.get_ylim() # Save figure and graph as images savefig(tutorial_image_name('png', suffix='1')) # Do more plotting fig = plt.figure() ax = plt.subplot(111) ax.minorticks_on() # ax.grid() ax.set_ylabel('f(x)') ax.set_title(r'$a\,\sin(x)+b\,\sin(kx)$') ax.autoscale(enable=True, axis='y') ax.set_ylim(ymin, ymax) ax.axhline(0.0, linestyle='--', color='black', linewidth=1.0, alpha=0.5) def plot_sample(): label = 'a={}, b={}, k={}'.format(*(p.value() for p in (pa, pb, pk)))
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')
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)