# Increase Heatmap Font Size in Seaborn

Salman Mehmood May 21, 2022

We start this article with the basics of the heatmap. We will learn what a heatmap is and how to annotate our heatmap.

We will also look at how to change our tick labels font size in a Seaborn heatmap.

## Increase Heatmap Font Size in Seaborn

The heatmap is a data visualization tool used to represent graphically the magnitude of data using colors. It helps identify values easily from a given set of data.

We will start by importing the Seaborn library, Matplotlib, and NumPy. We will load some data from Seaborn, which is about cars.

``````import seaborn as sb
import matplotlib.pyplot as plot
import numpy as np

``````

Each row gives the statistics about a specific car. Let’s go ahead and group up some of that data before building our heat map.

``````CARS.groupby('origin').cylinders.value_counts()
``````

We will group by origin or region where each car was made and then also look at the number of cylinders of each car. We are just doing a value count, so we know that there were 63 different cars with four cylinders from Europe, etc. We can see that these data have this multi-level index, so we need to unstack our data. We will fill those missing values with zeros.

``````ORIGIN_CYL=CARS.groupby('origin').cylinders.value_counts().unstack().fillna(0)
``````

Now we know how many cars were produced in each region with each number of cylinders. Now we are ready to build our first heatmap. To build a heatmap within Seaborn, we only need to reference the Seaborn library by calling up the `heatmap()` method and passing the `ORIGIN_CYL` data frame.

``````import seaborn as sb
import matplotlib.pyplot as plot
import numpy as np

CARS.groupby('origin').cylinders.value_counts()

ORIGIN_CYL=CARS.groupby('origin').cylinders.value_counts().unstack().fillna(0)
sb.heatmap(ORIGIN_CYL)
plot.show()
``````

We can now see the different rows and columns here, and we have mapped each of those values to a specific color. The lower values were mapped to the darker shades, and higher values were mapped to the lighter shades. We can transpose our heatmap pretty easily using the `T` property.

``````import seaborn as sb
import matplotlib.pyplot as plot
import numpy as np

CARS.groupby('origin').cylinders.value_counts()

ORIGIN_CYL=CARS.groupby('origin').cylinders.value_counts().unstack().fillna(0)
sb.heatmap(ORIGIN_CYL.T)
plot.show()
``````

It will completely invert our matrix. Now `cylinders` represent the rows, and `origins` represent columns. We can also style the annotations through an argument called `annot_kws`. This argument accepts the dictionary, and we can pass different types of properties.

We can change the `fontsize`, `fontweight`, and `fontfamily`.

``````import seaborn as sb
import matplotlib.pyplot as plot
import numpy as np

CARS.groupby('origin').cylinders.value_counts()

ORIGIN_CYL=CARS.groupby('origin').cylinders.value_counts().unstack().fillna(0)

sb.heatmap(ORIGIN_CYL,
cmap='Blues',
annot=True,
fmt=".0f",
annot_kws={
'fontsize': 16,
'fontweight': 'bold',
'fontfamily': 'serif'
}
)

plot.show()
``````

The `fontsize` property will increase our heatmap font size. We can resize those rectangles using a `square` argument. We can specify if we would like each of those rectangles to be a perfect square; we can turn this on by setting it equal to True.

``````import seaborn as sb
import matplotlib.pyplot as plot
import numpy as np

sb.heatmap(CARS.corr(),cmap='RdBu',square=True)

plot.show()
``````

Output: Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.