Heatmap. In this folder, we will go over how to create bar charts with Python and Plotly.
The following scripts are used in this chapter:
- Simple_heatmap.py
This chapter requires the following packages for the scripts used:
- Pandas
- Plotly
This chapter may use the following data from the Data folder:
- 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.
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
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
# 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()!
Plotly Documentation Heatmaps
