Esempio n. 1
0
 def _create_and_save_scatter_chart(self, player_shots_df, player_name):
     """
     Given a DataFrame object, save a scatter shot chart and return its path
     """
     if player_shots_df.SHOT_MADE_FLAG.count() > 0:
         chart_title = self._get_chart_title(player_name,
                                             CHART_KIND.SCATTER)
         filename = self._get_filename_from_player_name(
             player_name, CHART_KIND.SCATTER)
         player_shots_df_fg_made = player_shots_df.query(
             'SHOT_MADE_FLAG == 1')
         player_shots_df_fg_missed = player_shots_df.query(
             'SHOT_MADE_FLAG == 0')
         nba.shot_chart(player_shots_df_fg_missed.LOC_X,
                        player_shots_df_fg_missed.LOC_Y,
                        title=chart_title,
                        color=SHOT_COLOR.MISSED,
                        flip_court=True)
         nba.shot_chart(player_shots_df_fg_made.LOC_X,
                        player_shots_df_fg_made.LOC_Y,
                        title=chart_title,
                        color=SHOT_COLOR.MADE,
                        flip_court=True)
         return self._save_plot(filename)
     print "No data..."
     return None
Esempio n. 2
0
 def _create_and_save_hex_chart(self, player_shots_df, player_name):
     """
     Given a DataFrame object, save a hex shot chart and return its path
     """
     if player_shots_df.SHOT_MADE_FLAG.count() > 0:
         chart_title = self._get_chart_title(player_name, CHART_KIND.HEX)
         filename = self._get_filename_from_player_name(player_name, CHART_KIND.HEX)
         nba.shot_chart(player_shots_df.LOC_X,
                        player_shots_df.LOC_Y,
                        C=player_shots_df.SHOT_MADE_FLAG,
                        title=chart_title,
                        kind=CHART_KIND.HEX,
                        cmap=self.cmap,
                        gridsize=HEX_GRID_SIZE,
                        flip_court=True)
         return self._save_plot(filename)
     print "No data..."
     return None
Esempio n. 3
0
 def _create_and_save_hex_chart(self, player_shots_df, player_name):
     """
     Given a DataFrame object, save a hex shot chart and return its path
     """
     if player_shots_df.SHOT_MADE_FLAG.count() > 0:
         chart_title = self._get_chart_title(player_name, CHART_KIND.HEX)
         filename = self._get_filename_from_player_name(
             player_name, CHART_KIND.HEX)
         nba.shot_chart(player_shots_df.LOC_X,
                        player_shots_df.LOC_Y,
                        C=player_shots_df.SHOT_MADE_FLAG,
                        title=chart_title,
                        kind=CHART_KIND.HEX,
                        cmap=self.cmap,
                        gridsize=HEX_GRID_SIZE,
                        flip_court=True)
         return self._save_plot(filename)
     print "No data..."
     return None
Esempio n. 4
0
 def _create_and_save_scatter_chart(self, player_shots_df, player_name):
     """
     Given a DataFrame object, save a scatter shot chart and return its path
     """
     if player_shots_df.SHOT_MADE_FLAG.count() > 0:
         chart_title = self._get_chart_title(player_name, CHART_KIND.SCATTER)
         filename = self._get_filename_from_player_name(player_name, CHART_KIND.SCATTER)
         player_shots_df_fg_made = player_shots_df.query('SHOT_MADE_FLAG == 1')
         player_shots_df_fg_missed = player_shots_df.query('SHOT_MADE_FLAG == 0')
         nba.shot_chart(player_shots_df_fg_missed.LOC_X,
                        player_shots_df_fg_missed.LOC_Y,
                        title=chart_title,
                        color=SHOT_COLOR.MISSED,
                        flip_court=True)
         nba.shot_chart(player_shots_df_fg_made.LOC_X,
                        player_shots_df_fg_made.LOC_Y,
                        title=chart_title,
                        color=SHOT_COLOR.MADE,
                        flip_court=True)
         return self._save_plot(filename)
     print "No data..."
     return None