Skip to content

Latest commit

 

History

History
98 lines (84 loc) · 2.64 KB

File metadata and controls

98 lines (84 loc) · 2.64 KB

Heatmaps

Heatmap. In this folder, we will go over how to create bar charts with Python and Plotly.

Files

The following scripts are used in this chapter:

  • Simple_heatmap.py

Pacakges Needed

This chapter requires the following packages for the scripts used:

  • Pandas
  • Plotly

Data Used

This chapter may use the following data from the Data folder:

  • cust_num.csv

cust_num.csv

cust_num.csv is data set that records the customer traffic of a hypothetical department store by day of week and hours.

Syntax

Data

Data is a list to store go.Heatmap().

go.heatmap() has the following parameters:

  • x: Attribute on x-axis
  • y: Attribute on y-axis
  • z: Value of the attribute on x and y-axis, and display in colour
  • colorscale: The colour scale on how data is displayed, depends on z
  • hoverongaps: When there is missing value in the data, it will not show hovertext if this column is set to false (Default to true)
  • hoverinfo: What information to be displayed when user hover over the coloured area, all the options are:
    • percent
    • label+percent
    • label
    • name

Layout

Genetic Layout parameters suggested to use:

  • title (Dictionary): Chart title and fonts
    • text: Chart title to be displayed
    • x: text location on x-dimension, from 0-1
    • y: text location on y-dimension, from 0-1
  • xaxis (Dictionary): X-axis setting
    • tickmode: Setting of ticks
    • tickangle: Degree the tick rotate (-: Anticlockwise, +: Clockwise)
  • yaxis (Dictionary): y-axis setting
    • tickmode: Setting of ticks
    • tickangle: Degree the tick rotate (-: Anticlockwise, +: Clockwise)


Heatmap Exclusive parameters:

  • z: Value of the attribute on x and y-axis
  • hoverongaps: Display or not if data is missing

Examples

Example 1 - Simple Heatmap

# Data
data = []
data.append(go.Heatmap(z=df['customers_count'],
	                   x=df['day'], y=df['hour'],
	                   colorscale='ylorrd'))

# Layout
layout = {'title':{'text':'Department Store Traffic',
	               'x':0.5},
	      'xaxis': {'tickmode':'linear'},
	      'yaxis': {'tickmode':'linear'}}

Note: For some reason, z-axis must be declared before x-axis and y-axis in go.Heatmap()!

Reference

Plotly Documentation Heatmaps