Deploying an app in Heroku to test heatmap libraries and palettes in Python using Streamlit.

How to develop a simple app to see which is the most convenient library and color palette for our python visualizations.

Photo by moren hsu on Unsplash

All of us who work as data analysts and data scientists understand the importance of data visualization as a tool, and how powerful it is when showing us events and stories from data, especially today where there is an immense amount of information to analyze.

Heatmaps is an example of a data visualization technique that shows us the magnitude of an event using colors in two dimensional space.
The color variation (tone / intensity) give us a clue about the study phenomenon (concentration in an area, dispersion, maximum and minimum values, etc.)

I’ve been working with heatmaps for a while, and looking for the best way to represent the data that I analyze I had the idea of ​​developing this app that I share now, to evaluate the different libraries available and how each color palette impacts according to the case study.

What we need to start:

Front End:
Streamlit is an open-source app framework for Machine Learning and Data Science. It allows to create beautiful data apps in hours usign python​
No front‑end experience required

Python visualization libraries:

Each one has its advantages and disadvantages, in terms of simplicity, speed, interactivity, etc. It is up to each of us which one best suits the scenario that is being evaluated.

Source: Jake VanderPlas, “Python’s Visualization Landscape,” PyCon 2017
  • Altair:
    Altair is a declarative statistical visualization library for Python, based on Vega and Vega-Lite (JSON specification format that renders using the D3 visualization library).
    Allows spend more time understanding your data and its meaning.
    This elegant simplicity beautiful and effective visualizations with a minimal amount of code.
  • Bokeh:
    Library for interactive data visualization. Renders its graphics using HTML and JavaScript making it a great candidate for building web-based dashboards and applications rich grammar elements for chart elements and interactions
  • Holoviews:
    Open-source Python library designed to make data analysis and visualization seamless and simple.
    Very few lines of code, letting you focus on what you are trying to explore.
  • MatplotLib:
    Matplotlib is a python 2D plotting library which produces publication quality
    figures in a variety of hardcopy formats and interactive environments across platforms.
  • Seaborn:
    Is a data visualization library for Python developed on top of matplotlib.
    It offers a high-level interface for creating attractive graphics in a simple way.
  • PlotNine (Ggplot):
    plotnine is the python implementation of R’s library ggplot2.
    Ggplot2 is a system for declaratively creating graphics, based on The Grammar of Graphics book.
    You provide the data, tell ggplot2 how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details.
    The gg in “ggplot2” stands for Grammar of Graphics
  • Ploty:
    Is an interactive, open-source plotting library that supports over 40 unique chart types covering a wide range of statistical, financial, geographic, scientific, and 3-dimensional use-cases. User friendly and cross-platform support for python, R, and Javascript.
  • Cufflinks:
    According to its author, this library binds the power of plotly with the flexibility of pandas for easy plotting.
    Connects the Pandas data frame with Plotly enabling users to create visualizations directly from Pandas.
    Cufflinks is plotly with a different api, running from a pandas dataframe.

Lets code:

  • First, include all the libraries we need:
  • Add some support functions:

generateDf: For my sample I generate a dataset with weekly values ​​between 1920 and 2020 (48 weeks x 100 years) and populate it with random integers values.
It returns the original dataset and the matrix version for the libraries that use a matrix to generate the graph. This I do with a simple pivot on the first two columns leaving the third as the data to show in each cell of the heatmap

cmap2rgb: This function converts a matplotlib color palette (CMAP) into a list of RGB colors for some of the libraries.

loadDataset: use it to load the dataset from a .CSV file

timing: decorator function to show in each graphing function the size of the dataset and the time it takes to generate the heatmap.

getFile: load the dataset from a .CSV file using the streamlit interface.

  • Display functions:

Each library has its own encapsulated function to graph a standard heatmap.

  • Finally, the main function

explanation in the code comments

The final result can be seen through the following link:

https://heatmap-py.herokuapp.com/

Full source code:

https://github.com/vfrabasil/heatmap-py

Next chapter…, account configuration in Heroku and application upload.