def line_plot(): """Make a line plot of T along the vertical direction.""" if T.ufl_element().degree() != 1: T2 = interpolate(T, FunctionSpace(mesh, 'Lagrange', 1)) else: T2 = T T_box = scitools.BoxField.dolfin_function2BoxField( T2, mesh, divisions, uniform_mesh=True) #T_box = scitools.BoxField.update_from_dolfin_array( # T.vector().array(), T_box) coor, Tval, fixed, snapped = \ T_box.gridline(start_pt, direction=d-1) # Use just one ev.plot command, not hold('on') and two ev.plot # etc for smooth movie on the screen if kappa_0 == kappa_1: # analytical solution? ev.plot(coor, Tval, 'r-', coor, T_exact(coor), 'b-', axis=[-D, 0, T_R-T_A, T_R+T_A], xlabel='depth', ylabel='temperature', legend=['numerical', 'exact, const kappa=%g' % kappa_0], legend_loc='upper left', title='t=%.4f' % t) else: ev.plot(coor, Tval, 'r-', axis=[-D, 0, T_R-T_A, T_R+T_A], xlabel='depth', ylabel='temperature', title='t=%.4f' % t) ev.savefig('tmp_%04d.png' % counter) time.sleep(0.1)
x = y = np.linspace(-10., 10., 11) x2v, y2v = plt.ndgrid(x, y) # Define a coarser grid for the vector field h2v = h0 / (1 + (x2v**2 + y2v**2) / (R**2)) # Compute height for new grid dhdx, dhdy = np.gradient(h2v) # Compute the gradient vector (dh/dx,dh/dy) # Draw contours and gradient field of h plt.figure(9) plt.quiver(x2v, y2v, dhdx, dhdy, 0, 'r') plt.hold('on') plt.contour(xv, yv, hv) plt.axis('equal') # end draw contours and gradient field of h x = y = np.linspace(-5, 5, 11) xv, yv = plt.ndgrid(x, y) u = xv**2 + 2 * yv - .5 * xv * yv v = -3 * yv # Draw 2D-field plt.figure(10) plt.quiver(xv, yv, u, v, 200, 'b') plt.axis('equal') # end draw 2D-field plt.figure(9) plt.savefig('images/quiver_scitools_advanced.pdf') plt.savefig('images/quiver_scitools_advanced.png') plt.figure(10) plt.savefig('images/quiver_scitools_simple.pdf') plt.savefig('images/quiver_scitools_simple.png')
# 10 black ('k') contour lines plt.figure(6) plt.contour(xv, yv, hv, 10, 'k') # Specify the contour levels explicitly as a list plt.figure(7) levels = [500., 1000., 1500., 2000.] plt.contour(xv, yv, hv, levels=levels) # Add labels with the contour level for each contour line plt.figure(8) plt.contour(xv, yv, hv, clabels='on') #end contourplots plt.figure(1) plt.savefig('images/simple_plot_scitools.png') plt.savefig('images/simple_plot_scitools.pdf') plt.figure(2) plt.savefig('images/simple_plot_colours_scitools.png') plt.savefig('images/simple_plot_colours_scitools.pdf') plt.figure(3) plt.savefig('images/default_contour_scitools.pdf') plt.savefig('images/default_contour_scitools.png') plt.figure(4) plt.savefig('images/default_contour3_scitools.png') plt.savefig('images/default_contour3_scitools.pdf') plt.figure(5)
# Draw contours and gradient field of h plt.figure(9) plt.quiver(x2v, y2v, dhdx, dhdy, 0, 'r') plt.hold('on') plt.contour(xv, yv, hv) plt.axis('equal') # end draw contours and gradient field of h x = y = np.linspace(-5, 5, 11) xv, yv = plt.ndgrid(x, y) u = xv**2 + 2*yv - .5*xv*yv v = -3*yv # Draw 2D-field plt.figure(10) plt.quiver(xv, yv, u, v, 200, 'b') plt.axis('equal') # end draw 2D-field plt.figure(9) plt.savefig('images/quiver_scitools_advanced.pdf') plt.savefig('images/quiver_scitools_advanced.png') plt.figure(10) plt.savefig('images/quiver_scitools_simple.pdf') plt.savefig('images/quiver_scitools_simple.png')