How to Create an Animated Map of Bike Rentals in Chicago

How to Create an Animated Map of Bike Rentals in Chicago

Add animation to a visualization created with the Python package Bokeh. This article assumes the reader already knows how to plot geographic data using the Bokeh library in Python.

This article assumes the reader already knows how to plot geographic data using the Bokeh library in Python. For an excellent and thorough explanation, please see this [article_](https://towardsdatascience.com/exploring-and-visualizing-chicago-transit-data-using-pandas-and-bokeh-part-ii-intro-to-bokeh-5dca6c5ced10) written by [Colin Patrick Reid_](https://towardsdatascience.com/@colinpatrickreid).

Your data is processed and you’ve successfully adapted Colin’s code to create your own beautiful visualization in Bokeh, but you want to convey more information than is possible with a static image. You’re in the right place!

Initial Setup

We will start with this already processed data that combines bike rental data with historic daily average Chicago temperatures and the code below:

from bokeh.plotting import figure, show
    from bokeh.tile_providers import get_provider, Vendors
    import pandas as pd
    from bokeh.models import ColumnDataSource, HoverTool
    from bokeh.models import Label

    path = 'C:\\Map'
    df = pd.read_csv('https://raw.githubusercontent.com/mthomp12/Animated_Bike_Graph/master/bike_data.csv')

    df['circle_sizes'] = df['avg_trip_count'] / df['avg_trip_count'].max() * 40
    temps = df['temp'].unique().tolist()

    #only load in data for first temperature
    df = df[df['temp']==df['temp'].max()]

    source = ColumnDataSource(data=dict(
                            x=list(df['coords_x']), 
                            y=list(df['coords_y']),
                            ridership=list(df['avg_trip_count']),
                            sizes=list(df['circle_sizes']),
                            stationname=list(df['station_name'])))

    hover = HoverTool(tooltips=[
        ("station", "@stationname"),
        ("ridership","@ridership")

    ])

    p = figure(x_range=(-9759380, -9749918), y_range=(5140778, 5150200),
               x_axis_type="mercator", y_axis_type="mercator", tools=['pan',hover, 'wheel_zoom', 'save'])

    p.add_tile(get_provider(Vendors.CARTODBPOSITRON))

    p.circle(x = 'x',
             y = 'y',
             source=source,
             size='sizes',
            line_color="#FF0000", 
             fill_color="#FF0000",
             fill_alpha=0.05
            )

    #Legend
    rides = [50, 100, 200, 400]
    circles = [x / df['avg_trip_count'].max() * 40 for x in rides]
    x_coords = [-9752040] * 4
    y_coords = [5148472, 5148124, 5147752, 5147133]
    p.circle(x = x_coords, y = y_coords, size=circles, line_color="#FF0000", fill_color="#FF0000", fill_alpha=0.05)
    p.add_layout(Label(x = -9752100, y=5148672, text='Rides Per Day'))

    for x,y,text in zip(x_coords, y_coords, rides):
        p.add_layout(Label(x = x+(500 if text!=50 else 595), y=y-200, text=str(text)))

    loc =  (-9756040, 5148472)
    mytext = Label(x=loc[0], y=loc[1], text='Temp: 80\N{DEGREE SIGN}F', text_font_size='25pt')
    p.add_layout(mytext)
    #end legend

    show(p)

data-visualization python data-science bokeh

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Data Visualization With Python | Data Visualization | Python For Data Science

🔥To access the slide deck used in this session for Free, click here: https://bit.ly/GetPDF_DataV_P 🔥 Great Learning brings you this live session on 'Data Vis...

Applied Data Science with Python Certification Training Course -IgmGuru

Master Applied Data Science with Python and get noticed by the top Hiring Companies with IgmGuru's Data Science with Python Certification Program. Enroll Now

50 Data Science Jobs That Opened Just Last Week

Data Science and Analytics market evolves to adapt to the constantly changing economic and business environments. Our latest survey report suggests that as the overall Data Science and Analytics market evolves to adapt to the constantly changing economic and business environments, data scientists and AI practitioners should be aware of the skills and tools that the broader community is working on. A good grip in these skills will further help data science enthusiasts to get the best jobs that various industries in their data science functions are offering.

Data Visualization in Data Science

How to use graphs effectively while working on Analytical problems. Data visualization is the process of creating interactive visuals to understand trends, variations, and derive meaningful insights from the data. Data visualization is used mainly for data checking and cleaning, exploration and discovery, and communicating results to business stakeholders.

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.