# How could I go about creating a heatmap?

**URL:** <https://root-forum.cern.ch/t/how-could-i-go-about-creating-a-heatmap/47127>\
**Category:** Newbie\
**Created:** [October 5, 2021, 8:00pm UTC](https://root-forum.cern.ch/t/how-could-i-go-about-creating-a-heatmap/47127 "2021-10-05T20:00:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abunka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@abunka](https://root-forum.cern.ch/u/abunka)\
**Post date:** [October 5, 2021, 8:00pm UTC](https://root-forum.cern.ch/t/how-could-i-go-about-creating-a-heatmap/47127/1 "2021-10-05T20:00:08Z")

</div>

Hello  
What would be the best way to create a heat map of variables using root? The x and y axes would be lists of the variable names and the values would be some calculated quantity between the two variables (such as covariance).  
This seems to cover setting words in the axis tick labels:  
[[ROOT: TGaxis Class Reference](https://root.cern.ch/doc/master/classTGaxis.html#GA10)]  
And the COLor option outlined here:  
[[ROOT: THistPainter Class Reference](https://root.cern/doc/v610/classTHistPainter.html#HP14)]  
Is close to what I want, but I would need to be able to set each bin to a single numerical value.  
I could not find anything for a heatmap on the forums.  
Thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [October 6, 2021, 3:58am UTC](https://root-forum.cern.ch/t/how-could-i-go-about-creating-a-heatmap/47127/2 "2021-10-06T03:58:33Z")

</div>

You can use [TH2::SetBinContent](https://root.cern/doc/master/classTH2.html#ac30f05d1fa38d839ff20829d85ba10fe).

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [October 6, 2021, 8:05am UTC](https://root-forum.cern.ch/t/how-could-i-go-about-creating-a-heatmap/47127/3 "2021-10-06T08:05:41Z")

</div>

> [@abunka](#):
>
> The x and y axes would be lists of the variable names

It seems you are looking for a TH2 with alphanumeric labels as shown is [this example](https://root.cern/doc/master/hlabels2_8C.html). To fill the histogram you can use `SetBinContent()` as suggested by @dastudillo . In the example I mentioned the histogram is plotted with the option `TEXT`. Use the option `COLZ` instead in order to get a heatmap. ROOT offers a wide collection of [predefined palettes](https://root.cern/doc/master/classTColor.html#C06). You might find one you like.
