Color schemes

Color schemes#

Interactive Content Ahead! 🚨

This page features interactive content that do not work within the course’s static website. To fully engage with these materials, consider accessing them through environments like CSC/JupyterLab. If you’re viewing this page on the course’s website and wish to load the interactive elements, please use Binder. Look for the Binder icon—a small rocket logo—at the top of the page to get started.

Let’s compare the color schemes and discuss around the following aspects:

  • Data Suitability: How well does the color scheme convey the nature of the data? Is it sequential, diverging, or qualitative?

  • Visual Perception: Does the color scheme offer a perceptually uniform progression, making it easy to interpret changes in data values?

  • Accessibility: How accessible is the color scheme for people with color vision deficiencies?

  • Emotional Impact: Do certain colors evoke specific emotions or cultural associations that could influence the interpretation of the data?

[4]:
import geopandas as gpd
import matplotlib.pyplot as plt
import ipywidgets as widgets
from IPython.display import display, clear_output
# Load the GeoPackage data
data_path = 'data/helsinki_region_travel_times_to_railway_station.gpkg'
gdf = gpd.read_file(data_path)
gdf = gdf[gdf['pt_r_t'] > 0]
# Create the dropdown widget for color scheme selection
color_dropdown = widgets.Dropdown(
    options=['viridis', 'plasma', 'inferno', 'magma', 'cividis'],
    value='viridis',
    description='Color Scheme:',
)

# Create an output widget to manage the plot output
color_dropdown = widgets.Dropdown(
    options=[
        'viridis', 'plasma', 'inferno', 'magma', 'cividis',
        'coolwarm', 'Spectral', 'spring', 'summer', 'autumn',
        'winter', 'Wistia', 'hot', 'afmhot', 'gist_heat',
        'copper', 'PiYG', 'PRGn', 'BrBG', 'PuOr',
        'RdGy', 'RdBu', 'RdYlBu', 'RdYlGn', 'Spectral',
        'cool', 'rainbow', 'jet', 'hsv'
    ],
    value='viridis',
    description='Color Scheme:',
)

# Create an output widget to manage the plot output
plot_output = widgets.Output()

def plot_map(color_scheme):
    with plot_output:
        clear_output(wait=True)  # Clear the previous plot
        fig, ax = plt.subplots(figsize=(10, 10))
        gdf.plot(column='pt_r_t', cmap=color_scheme, legend=True, ax=ax,  legend_kwds={"label": "Travel time (min)", "location":"left", "shrink": 0.5} )
        plt.title(f'Helsinki Region Travel Times with "{color_scheme}" Color Scheme')
        # Hide the axis labels
        ax.set_xlabel('')
        ax.set_ylabel('')

        # Hide the tick marks and labels on both axes
        ax.tick_params(axis='both', which='both', length=0)
        ax.set_xticklabels([])
        ax.set_yticklabels([])
        ax.xaxis.set_ticks_position('none')
        ax.yaxis.set_ticks_position('none')
        plt.show()

def on_color_change(change):
    plot_map(change.new)

color_dropdown.observe(on_color_change, names='value')

# Display the widgets
display(color_dropdown, plot_output)