Let’s dive in.
Function Syntax and Parameter List
The function syntax is as shown in the following code snippet:
annotation_text=None, colorscale='Plasma', font_colors=None, showscale=False,
The following are some important function parameters that you will use when working with this function:
- z – Defines the matrix used to create the annotated heatmap.
- x – Sets the values for the x axis labels.
- y – Defines the values for the y axis labels.
- colorscale – Sets the colorscale for the heatmap.
- reverscale – Sets a reverse colorscale.
Basic Annotated Heatmap
The following code illustrates how to create a simple annotated heatmap using the figure_factory function.
z = z = [[.1, .3, .5, .7, .9],
[1, .8, .6, .4, .2],
[.2, 0, .5, .7, .9],
[.9, .8, .4, .2, 0],
[.3, .4, .5, .7, 1]]
fig = create_annotated_heatmap(z)
The previous code returns a heatmap as shown in the following illustration:
By default, the colorscale is disabled by default. You can enable it by setting the showscale parameter to True as shown in the following:
The output figure is as shown in the following:
We can also set a custom colorscale by setting the colorscale parameter. An example is as follows:
The resulting figure is as shown in the following illustration:
In this article, we explored how to create the annotated heatmap plots using the Plotly figure_factory module.
Thanks for reading. Happy coding!