Heatmap visualization

The heatmap visualization allows you to visualize numerical data using colors. A common color palette for a heatmap shows the highest values using warmer colors, like orange or red, and the lowest values using cooler colors, like blue or purple. For example, consider the following heatmap that visualizes the most frequently occurring distances of taxi rides on each day and groups the results by the day of the week, distance, and the total fare and the query used to create it. The query uses the samples.nyctaxi.trips table and you can try it in your workspace with no set-up required.

Trip fare heatmap

To create a heatmap visualization:

  1. In the SQL editor, run a query.
  2. Click Add Visualization.
  3. From the drop-down, select Heatmap.

This query of the samples.nyctaxi.trips table returns the most frequently occurring distances of taxi rides on each day and groups the results by the day of the week, distance, and the total fare:

with base as (
  select
    weekday(tpep_pickup_datetime) weekday,
    CASE
      weekday(tpep_pickup_datetime)
      WHEN 0 THEN 'Sunday'
      WHEN 1 THEN 'Monday'
      WHEN 2 THEN 'Tuesday'
      WHEN 3 THEN 'Wednesday'
      WHEN 4 THEN 'Thursday'
      WHEN 5 THEN 'Friday'
      WHEN 6 THEN 'Saturday'
    END day,
    cast(trip_distance / {{ specificity in miles }} as integer) dist,
    avg(fare_amount) fare
  from
    samples.nyctaxi.trips
  group by
    1,
    2,
    3
)
select
  *
from
  base
order by
  weekday desc

The query has one parameter, Specificity in miles.

To quickly visualize when trips with the highest fares occurred, the heatmap uses the following settings:

  • X-axis: Trip distance
  • Y-axis columns: Days of the week
  • Color column: Fare

Create a heatmap visualization

To create a heatmap visualization:

  1. In the SQL editor, create and run a query.
  2. In the bottom right editor panel, click + Add Visualization.
  3. Configure the options in the following sections.

You can preview the effect of each configuration option you change. Click Save to apply all changes.

General

To configure general options, click General and configure each of the following required settings:

  • X Column: The part of the query result to use to divide the data into rows, such as days of the week.
  • Y Columns: The part of the query result to use to divide the data into rows, such as trip distance.
  • Color Column: The part of the query result that determines the color for each grid area, such as trip fare.

X-Axis

To configure formatting options for the X-axis, click X-Axis and configure the following optional settings:

  • Scale: Override the automatically-detected scale with one of Linear or Logorithmic.
  • Name: Override the column name with a different display name.
  • Sort Values: Whether to sort the X-axis values, even if they are not sorted in the query.
  • Reverse Order: Whether to reverse the sorting order.
  • Show Labels Whether to show the X-axis values as labels.
  • Hide Axis: If enabled, hides the X-axis labels and scale markers.

Y-Axis

To configure formatting options for the Y-axis, click Y-Axis and configure the following optional settings:

  • Scale: Override the automatically-detected scale with one of the following: Datetime, Linear, Logorithmic, or Category.
  • Name: Override the column name with a different display name.
  • Min Value: Show only values higher than a given value, regardless of the query result.
  • Max Value: Show only values lower than a given value, regardless of the query result.
  • Sort Values: Whether to sort the X-axis values, even if they are not sorted in the query.
  • Reverse Order: Whether to reverse the sorting order.

Colors

To override the cefault color scheme for the visualization, click Colors and set the Color Scheme drop-down to a color scheme.

Data labels

To configure labels for each data point in the visualization, click Data Labels and configure the following optional settings:

  • Show Data Labels: Whether to show data labels. Data labels can add visual clutter and are usually disabled for heatmaps.
  • Number Values Format: The format to use for labels for numeric values.
  • Percent Values Format: The format to use for labels for percentages.
  • Date/Time Values Format: The format to use for labels for date/time values.
  • Data Labels: The format to use for lavbels for other types of values.

Edit a visualization

To edit a visualization, click its tab on the tab bar, then click the Edit Visualization button beneath the visualization.

Temporarily hide or show only a series

To hide a series in a visualization, click the series in the legend. To show the series again, click it again in the legend.

To show only a single series, double-click the series in the legend. To show other series, click each one.