• AIPressRoom
  • Posts
  • Easy methods to Create a Publication-High quality Heatmap in Python | by Stephen Fordham | Aug, 2023

Easy methods to Create a Publication-High quality Heatmap in Python | by Stephen Fordham | Aug, 2023

A tutorial information on heatmaps in Python

Introduction

Heatmaps can be utilized as informative figures to convey quantitative information. They can be utilized to convey information in an easy-to-read format offering a concise information abstract.

Python has a variety of instruments to facilitate the manufacturing of publication high quality heatmaps. These embody the Seaborn and Matplotlib libraries, along with the subplot2grid libraries which may present a handy strategy to organise information in a heatmap.

On this tutorial, I’ll element the steps required to provide a heatmap which focuses on the presence/absence of key parts. To do that, I’ll use a CSV file containing fictitious information a few collection of bacterial isolates. These bacterial strains have a variety of options together with antibiotic resistance genes, virulence genes, and sure capsule sorts. A heatmap will permit the fast inspection and comparability between the assorted strains.

Whereas the instance used focuses on bacterial strains, the strategies utilized can be utilized extra broadly for different datasets that will help you visualised your information utilizing a heatmap. All through the next tutorial, all pictures are by the writer.

Goal

To create a publication high quality heatmap displaying the presence/absence of key genes from fictitious bacterial strains.

This tutorial will use the next csv file, ‘Bacterial_strain_heatmap_tutorial_data.csv’ out there from the Github repository.

Getting began

To start, just a few imports are essential to learn within the information and stylise the determine later. We’ll start by together with all the import statements collectively.

import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colours import ListedColormap
import seaborn as sns
from matplotlib.patches import Patch
from matplotlib.traces import Line2D
from matplotlib.patches import Rectangle

Subsequent, we learn within the dataframe, set the index utilizing the column ‘Pressure’ and examine the primary 5 rows.

df = pd.read_csv('Bacterial_strain_heatmap_tutorial_data.csv').set_index('Pressure')…