#! /usr/bin/env python3 # def flow_vector ( ): #*****************************************************************************80 # ## flow_vector() draws a vector field (U,V)(X,Y). # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 February 2023 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np from matplotlib import cm print ( '' ) print ( 'flow_vector():' ) print ( ' Plot a vector field (U,V)(X,Y).' ) m = 16 n = 16 xvec = np.linspace ( 0, 1.0, n ) yvec = np.linspace ( 0, 1.0, m ) X, Y = np.meshgrid ( xvec, yvec ) U = - ( X**4 - 2 * X**3 + X**2 ) * ( 2 * Y**3 - 3 * Y**2 + Y ) V = ( 2 * X**3 - 3 * X**2 + X ) * ( Y**4 - 2 * Y**3 + Y**2 ) # # Form the figure. # plt.quiver ( X, Y, U, V, color = 'c' ) plt.axis ( 'equal' ) plt.title ( 'Vector field', fontsize = 16 ) plt.xlabel ( '<--- X --->', fontsize = 16 ) plt.ylabel ( '<--- Y --->', fontsize = 16 ) filename = 'flow_vector.png' plt.savefig ( filename ) print ( ' Graphics saved as "%s"' % ( filename ) ) plt.show ( ) plt.close ( ) return if ( __name__ == '__main__' ): flow_vector ( )