code: def movie_network():
      template = jenv.get_template("movie_network.html")
      context = dict()
      cl = client.get_client()
      session = cl.create_session()
      query = session.query(models.Movie.id,
                            models.Movie.name,
                            models.Movie.url,
                            models.Movie.budget_inflation_adjusted,
                            models.Movie.imdb_rating)
      movies = cl.df_query(query)
      query = session.query(models.MovieAppearance.movie_id,
                            models.MovieAppearance.character_id)
      appearances = cl.df_query(query)
      query = session.query(models.Character.id,
                            models.Character.url,
                            models.Character.name) \
          .filter(models.Character.id.in_([int(i) for i in appearances['character_id'].unique()]))
      characters = cl.df_query(query)
      graph = dict(nodes=[],
                   graph=[],
                   links=[],
                   directed=False,
                   multigraph=True)
      movie_node_id = dict()
      character_node_id = dict()
      movie_size_factor = 100. / movies['budget_inflation_adjusted'].max()
      for _, data in movies.iterrows():
          movie_node_id[data['id']] = len(graph['nodes'])
          graph['nodes'].append(dict(id=data['name'],
                                     size=max(5., data['budget_inflation_adjusted'] * movie_size_factor),
                                     score=data['imdb_rating'] / 10.,
                                     type='square',
                                     url="http://marvel.wikia.com" + data['url']))
      for _, data in characters.iterrows():
          character_node_id[data['id']] = len(graph['nodes'])
          graph['nodes'].append(dict(id=data['name'],
                                     size=10,
                                     type='circle',
                                     url="http://marvel.wikia.com" + data['url']))
      for _, data in appearances.iterrows():
          graph['links'].append(dict(source=movie_node_id[data['movie_id']],
                                     target=character_node_id[data['character_id']]))
      context['graph'] = json.dumps(graph, indent=4)
      out_file = path.join(out_dir, "movie_network.html")
      html_content = template.render(**context)
      with open(out_file, 'w') as f:
          f.write(html_content)
      plt.close('all')
      session.close()