parameters: (self, xlim=None, ylim=None, fig=True)
return_statement: return fig
docstring: Plot the Riemann fan for this problem.
docstring_summary: Plot the Riemann fan for this problem.
docstring_tokens: Plot the Riemann fan for this problem .
function: def fan_plot(self, xlim=None, ylim=None, fig=True):
          """Plot the Riemann fan for this problem."""
          import matplotlib.pyplot as plt
          if xlim is None:
              xlim = [-1, 1]
          if ylim is None:
              ylim = [0, 1]
          xlim = np.atleast_1d(xlim)
          ylim = np.atleast_1d(ylim)
          dx = np.diff(xlim)[0]
          dy = np.diff(ylim)[0]
          y = np.array([0, ylim.max() + dy])
          ws = self.waves
  
          lws = {'shock': 3, 'contact': 1}
          if fig is True:
              fig = plt.figure()
          for w in ws:
              if w['kind'] == 'simple':
                  plt.fill_betweenx(y, y * w['speed'][0], y * w['speed'][1], edgecolor='k',
                                    facecolor='.7', linestyle='-.')
              else:
                  plt.plot(y * w['speed'][0], y, 'k-', lw=lws[w['kind']])
          plt.xlim(*xlim)
          plt.ylim(*ylim)
          plt.axis('off')
          plt.axes().set_aspect('equal')
          opt = dict(fontsize=12, ha='center', va='center')
          r = ylim.min() + .8 * dy
          th = .5 * np.pi + .5 * np.arctan2(1, ws[0]['speed'][0])
          plt.text(r * np.cos(th), r * np.sin(th), r'$\mathbf{U}_{L}$', **opt)
          th = .5 * np.arctan2(1, ws[0]['speed'][1]) + .5 * \
              np.arctan(1. / ws[1]['speed'][0])
          plt.text(r * np.cos(th), r * np.sin(th), r'$\mathbf{U}_{L*}$', **opt)
          th = .5 * np.arctan2(1, ws[1]['speed'][1]) + .5 * \
              np.arctan(1. / ws[2]['speed'][0])
          plt.text(r * np.cos(th), r * np.sin(th), r'$\mathbf{U}_{R*}$', **opt)
          th = .5 * np.arctan2(1, ws[2]['speed'][1])
          plt.text(r * np.cos(th), r * np.sin(th), r'$\mathbf{U}_{R}$', **opt)
          opt.pop('ha')
          opt.pop('va')
          aopt = dict(xycoords='data', textcoords='data',
                      arrowprops=dict(arrowstyle="<-", lw=2, color='.3'))
          plt.annotate("", xy=(xlim.min(), 0), xytext=(xlim.max(), 0), **aopt)
          plt.annotate("", xy=(0, ylim.min()), xytext=(0, ylim.max()), **aopt)
          plt.text(0, ylim.max() + .05 * dy, '$t$', ha='center', va='bottom', **opt)
          plt.text(xlim.max() + .025 * dx, 0, '$x$', ha='left', va='center', **opt)
  
          return fig
function_tokens: def fan_plot ( self , xlim = None , ylim = None , fig = True ) : import matplotlib . pyplot as plt if xlim is None : xlim = [ - 1 , 1 ] if ylim is None : ylim = [ 0 , 1 ] xlim = np . atleast_1d ( xlim ) ylim = np . atleast_1d ( ylim ) dx = np . diff ( xlim ) [ 0 ] dy = np . diff ( ylim ) [ 0 ] y = np . array ( [ 0 , ylim . max ( ) + dy ] ) ws = self . waves lws = { 'shock' : 3 , 'contact' : 1 } if fig is True : fig = plt . figure ( ) for w in ws : if w [ 'kind' ] == 'simple' : plt . fill_betweenx ( y , y * w [ 'speed' ] [ 0 ] , y * w [ 'speed' ] [ 1 ] , edgecolor = 'k' , facecolor = '.7' , linestyle = '-.' ) else : plt . plot ( y * w [ 'speed' ] [ 0 ] , y , 'k-' , lw = lws [ w [ 'kind' ] ] ) plt . xlim ( * xlim ) plt . ylim ( * ylim ) plt . axis ( 'off' ) plt . axes ( ) . set_aspect ( 'equal' ) opt = dict ( fontsize = 12 , ha = 'center' , va = 'center' ) r = ylim . min ( ) + .8 * dy th = .5 * np . pi + .5 * np . arctan2 ( 1 , ws [ 0 ] [ 'speed' ] [ 0 ] ) plt . text ( r * np . cos ( th ) , r * np . sin ( th ) , r'$\mathbf{U}_{L}$' , * * opt ) th = .5 * np . arctan2 ( 1 , ws [ 0 ] [ 'speed' ] [ 1 ] ) + .5 * np . arctan ( 1. / ws [ 1 ] [ 'speed' ] [ 0 ] ) plt . text ( r * np . cos ( th ) , r * np . sin ( th ) , r'$\mathbf{U}_{L*}$' , * * opt ) th = .5 * np . arctan2 ( 1 , ws [ 1 ] [ 'speed' ] [ 1 ] ) + .5 * np . arctan ( 1. / ws [ 2 ] [ 'speed' ] [ 0 ] ) plt . text ( r * np . cos ( th ) , r * np . sin ( th ) , r'$\mathbf{U}_{R*}$' , * * opt ) th = .5 * np . arctan2 ( 1 , ws [ 2 ] [ 'speed' ] [ 1 ] ) plt . text ( r * np . cos ( th ) , r * np . sin ( th ) , r'$\mathbf{U}_{R}$' , * * opt ) opt . pop ( 'ha' ) opt . pop ( 'va' ) aopt = dict ( xycoords = 'data' , textcoords = 'data' , arrowprops = dict ( arrowstyle = "<-" , lw = 2 , color = '.3' ) ) plt . annotate ( "" , xy = ( xlim . min ( ) , 0 ) , xytext = ( xlim . max ( ) , 0 ) , * * aopt ) plt . annotate ( "" , xy = ( 0 , ylim . min ( ) ) , xytext = ( 0 , ylim . max ( ) ) , * * aopt ) plt . text ( 0 , ylim . max ( ) + .05 * dy , '$t$' , ha = 'center' , va = 'bottom' , * * opt ) plt . text ( xlim . max ( ) + .025 * dx , 0 , '$x$' , ha = 'left' , va = 'center' , * * opt ) return fig