Python Examples

The following are 1 code examples for showing how to use These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module , or try the search function .

Example 1
Project: cfanalytics   Author: raybellwaves   File:    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _plot_city(self, ds):
        """Plot the results of gyms in a city.
        self.ds_sorted : xr.Dataset
            xr.Dataset with Coordinates: gyms.
        matplotlib.pyplot.figure : matplotlib.pyplot.figure
            Creates city plot.        
        # Create extend of map [W, E, S, N]
        extent = [ds['longitude'].values.min(), ds['longitude'].values.max(),
                  ds['latitude'].values.min(), ds['latitude'].values.max()]

        # Setup colors
        colors = cm.nipy_spectral(np.linspace(0,1,len(ds['gyms'])))
        # Get google map. Scale is for more details. Mapytype can have
        # 'terrain' or 'satellite'
        g = GoogleVisibleMap(x=[extent[0], extent[1]], y=[extent[2],
                                extent[3]], scale=4, maptype='terrain')
        ggl_img = g.get_vardata()
        # Plot map
        fig, ax = plt.subplots(1, 1, figsize=(20,20))
        sm = Map(g.grid, factor=1, countries=False)
        # Plot gym points
        for i in range(0, len(ds['gyms'])):
            # Create label
            self.regcount = i
            self._rank() # Add self.rank
            _label = self.rank+' '+ds['gyms'].values[i]+': '+\
            ds['athlete_names'].values[i]+' ('+str(ds[].values[i])+')'
            x, y = sm.grid.transform(ds['longitude'].values[i],
            ax.scatter(x, y, color=colors[i], s=400, label=_label)
        plt.title(self.fname+' | '' | '+self.column+' | '

        # Shrink current axis by 20% to make room for legend
        box = ax.get_position()
        ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
        ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
          '.png', bbox_inches = 'tight')
        #  '.png', bbox_inches = 'tight', format='eps')