

{"id":22567,"date":"2018-07-25T04:00:54","date_gmt":"2018-07-25T04:00:54","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=22567"},"modified":"2026-04-29T16:07:00","modified_gmt":"2026-04-29T10:37:00","slug":"python-heatmap-word-cloud","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/","title":{"rendered":"Python Heatmap | Word Cloud Python with Example"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:149,&quot;href&quot;:&quot;https:\\\/\\\/www.python.org&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251206090101\\\/https:\\\/\\\/www.python.org\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-06 12:20:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-09 12:44:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-12 13:49:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-15 14:13:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-18 15:26:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-21 17:05:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-24 19:33:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-28 02:44:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-31 04:43:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-03 07:01:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-06 07:15:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-09 07:16:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-12 10:01:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 10:07:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-18 10:11:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-21 10:20:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-24 10:47:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-27 10:58:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-30 10:59:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-02 12:28:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-05 13:05:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-08 15:11:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-11 15:46:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-14 17:21:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-17 18:37:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-20 18:52:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-23 19:52:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 01:02:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 03:50:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-05 05:18:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-08 06:18:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-11 07:24:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-14 08:33:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 08:58:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-20 12:26:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-23 14:32:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 16:21:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-29 17:22:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-01 18:18:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-04 18:27:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 02:33:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 04:53:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 06:48:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-17 07:17:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 07:32:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-23 09:34:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-26 10:13:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-29 10:35:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-02 11:50:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-05 12:07:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-08 13:08:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-11 14:46:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-14 21:24:09&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-18 03:08:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-21 06:27:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-24 07:06:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-27 07:30:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-30 08:47:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-02 09:37:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-05 09:43:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-08 10:40:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-11 10:49:02&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-11 10:49:02&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p><span style=\"font-weight: 400\">Next in our series of graphs and plots with<a href=\"https:\/\/data-flair.training\/blogs\/python-tutorial-for-beginners\/\" target=\"_blank\" rel=\"noopener\"><strong> Python<\/strong><\/a> is Python Heatmaps and Word Cloud. Moreover, we will see what a Python Heatmap and a Python Word Cloud are. Also, we will discuss the Python heatmap example and the Word Cloud Python Example.\u00a0<\/span><\/p>\n<p>So, let&#8217;s start with creating a Python Heatmap.<\/p>\n<h3><strong>How to Create a Heatmap in Python?<\/strong><\/h3>\n<p><span style=\"font-weight: 400\">So,<em> what is a heat map<\/em>? A way of representing data as a matrix of values. Basically, using different colors to represent data, it gives you a general view of the numerical data. Some manipulations when working with heatmaps. Python Heatmap\u00a0<\/span><span style=\"font-weight: 400\">includes normalizing the matrices, performing cluster analysis, choosing a color palette, and permuting rows and columns to place similar values nearby.<\/span><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-numpy-tutorial\/\" target=\"_blank\" rel=\"noopener\">Do you know about Python Numpy<\/a><\/strong><\/p>\n<h4><strong>a. A Simple Python Heatmap Example<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">First, let\u2019s make a simple heat map to get an idea of what it is.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import seaborn as sn\r\n&gt;&gt;&gt; import numpy as np\r\n&gt;&gt;&gt; import pandas as pd\r\n&gt;&gt;&gt; df=pd.DataFrame(np.random.random((7,7)),columns=['a','b','c','d','e','f','g'])\r\n&gt;&gt;&gt; sn.heatmap(df)<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x078DAA10&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import matplotlib.pyplot as plt\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22596\" style=\"width: 541px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/heatmap.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22596\" class=\"wp-image-22596 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/heatmap.png\" alt=\"Python Heatmap\" width=\"531\" height=\"432\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/heatmap.png 531w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/heatmap-150x122.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/heatmap-300x244.png 300w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/a><p id=\"caption-attachment-22596\" class=\"wp-caption-text\">Python Heatmap example<\/p><\/div>\n<p><span style=\"font-weight: 400\">Here, we create a DataFrame and then call the heatmap() method on it, borrowing from seaborn.<\/span><\/p>\n<h4><strong>b. Annotating your Python heatmap<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">You can add an annotation to every cell of your Python heatmap.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sn.heatmap(df,annot=True,annot_kws={'size':7})<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x078529D0&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22597\" style=\"width: 533px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/annotate.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22597\" class=\"wp-image-22597 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/annotate.png\" alt=\"Python Heatmap\" width=\"523\" height=\"433\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/annotate.png 523w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/annotate-150x124.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/annotate-300x248.png 300w\" sizes=\"auto, (max-width: 523px) 100vw, 523px\" \/><\/a><p id=\"caption-attachment-22597\" class=\"wp-caption-text\">Python Heatmap Annotation<\/p><\/div>\n<p><span style=\"font-weight: 400\">Here, annot_kws lets us set the size of the annotations with the \u2018size\u2019 parameter. We set it to 7 for this demo.<\/span><\/p>\n<h4><strong>c. Adding Grid Lines<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">It is possible to add grid lines to your Python heatmap. In the following piece of code, we add pink grid lines of thickness 2.5.<\/span><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/scipy-tutorial\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s discuss Python Scipy<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sn.heatmap(df,linewidths=2.5,linecolor='pink')<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x07AFD970&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22598\" style=\"width: 538px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/gridlines.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22598\" class=\"wp-image-22598 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/gridlines.png\" alt=\"Python Heatmap\" width=\"528\" height=\"430\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/gridlines.png 528w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/gridlines-150x122.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/gridlines-300x244.png 300w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/a><p id=\"caption-attachment-22598\" class=\"wp-caption-text\">rid lines in Python Heatmap<\/p><\/div>\n<h4><strong>d. Removing X or Y labels<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">In the next piece of code, we remove the x tick labels from the map.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sn.heatmap(df,xticklabels=False)<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x07B5F0D0&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22600\" style=\"width: 532px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xticklabels.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22600\" class=\"wp-image-22600 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xticklabels.png\" alt=\"Python Heatmap\" width=\"522\" height=\"406\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xticklabels.png 522w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xticklabels-150x117.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/xticklabels-300x233.png 300w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/a><p id=\"caption-attachment-22600\" class=\"wp-caption-text\">Removing labels in Python Heatmap<\/p><\/div>\n<h4><strong>e. Removing the color bar<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">The vertical bar at the extreme right of this Python Heatmap tells us what values the colors represent. But we can choose to not display it.<\/span><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-array-module\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s revise Python Array Module<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sn.heatmap(df,cbar=False)<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x08083090&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22603\" style=\"width: 451px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/colorbar.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22603\" class=\"wp-image-22603 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/colorbar.png\" alt=\"Python Heatmap\" width=\"441\" height=\"435\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/colorbar.png 441w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/colorbar-150x148.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/colorbar-300x296.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/colorbar-100x100.png 100w\" sizes=\"auto, (max-width: 441px) 100vw, 441px\" \/><\/a><p id=\"caption-attachment-22603\" class=\"wp-caption-text\">Removing color bar in Heatmap<\/p><\/div>\n<h4><strong>f. Keeping only a few labels<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">Basically, when there are too many cells\/labels, there may be overlapping. To avoid this, you can give a value <\/span><i><span style=\"font-weight: 400\">x<\/span><\/i><span style=\"font-weight: 400\"> to the xticklabels parameter. It then shows labels every <\/span><i><span style=\"font-weight: 400\">x<\/span><\/i><span style=\"font-weight: 400\"> labels.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sn.heatmap(df,xticklabels=2)<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x082E4C70&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22602\" style=\"width: 523px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/somelabels.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22602\" class=\"wp-image-22602 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/somelabels.png\" alt=\"Python Heatmap\" width=\"513\" height=\"421\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/somelabels.png 513w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/somelabels-150x123.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/somelabels-300x246.png 300w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/a><p id=\"caption-attachment-22602\" class=\"wp-caption-text\">Keeping few labels inPython heatmap<\/p><\/div>\n<h4>g. Choosing a color theme for your heatmap<\/h4>\n<p><span style=\"font-weight: 400\">Let\u2019s try a green.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sn.heatmap(df,cmap='Greens')<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x0AF5D510&gt;<\/strong><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-descriptive-statistics\/\" target=\"_blank\" rel=\"noopener\">Read Python Descriptive Statistics<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22604\" style=\"width: 523px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/greens.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22604\" class=\"wp-image-22604 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/greens.png\" alt=\"Python Heatmap\" width=\"513\" height=\"426\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/greens.png 513w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/greens-150x125.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/greens-300x249.png 300w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/a><p id=\"caption-attachment-22604\" class=\"wp-caption-text\">Heatmap &#8211; Color Theme<\/p><\/div>\n<p><span style=\"font-weight: 400\">Now, let\u2019s try blue and purple.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sn.heatmap(df,cmap='BuPu')<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x0B0CFAB0&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22606\" style=\"width: 527px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/purple.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22606\" class=\"wp-image-22606 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/purple.png\" alt=\"Python Heatmap\" width=\"517\" height=\"419\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/purple.png 517w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/purple-150x122.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/purple-300x243.png 300w\" sizes=\"auto, (max-width: 517px) 100vw, 517px\" \/><\/a><p id=\"caption-attachment-22606\" class=\"wp-caption-text\">Heatmap Python &#8211; Color theme<\/p><\/div>\n<p>Yellow, green, and blue-<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sn.heatmap(df,cmap='YlGnBu')<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x0B26F1D0&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22607\" style=\"width: 528px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/yellow-green-blue.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22607\" class=\"wp-image-22607 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/yellow-green-blue.png\" alt=\"Python Heatmap\" width=\"518\" height=\"421\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/yellow-green-blue.png 518w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/yellow-green-blue-150x122.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/yellow-green-blue-300x244.png 300w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/a><p id=\"caption-attachment-22607\" class=\"wp-caption-text\">Heatmap in Python &#8211; Color Theme<\/p><\/div>\n<p><span style=\"font-weight: 400\">Red, yellow, blue-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; sn.heatmap(df,cmap='RdYlBu')<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x09DF3A70&gt;<\/strong><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-interpreter\/\" target=\"_blank\" rel=\"noopener\">Have a look at the Python Interpreter<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22608\" style=\"width: 527px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/red-yellow-blue.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22608\" class=\"wp-image-22608 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/red-yellow-blue.png\" alt=\"Python Heatmap\" width=\"517\" height=\"433\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/red-yellow-blue.png 517w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/red-yellow-blue-150x126.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/red-yellow-blue-300x251.png 300w\" sizes=\"auto, (max-width: 517px) 100vw, 517px\" \/><\/a><p id=\"caption-attachment-22608\" class=\"wp-caption-text\">Heatmap Python &#8211; Color theme<\/p><\/div>\n<h4><strong>h. Plotting a discrete heatmap<\/strong><\/h4>\n<div id=\"attachment_22610\" style=\"width: 535px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/discrete.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22610\" class=\"wp-image-22610 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/discrete.png\" alt=\"Python Heatmap\" width=\"525\" height=\"430\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/discrete.png 525w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/discrete-150x123.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/discrete-300x246.png 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a><p id=\"caption-attachment-22610\" class=\"wp-caption-text\">Plotting a discrete heatmap<\/p><\/div>\n<p><span style=\"font-weight: 400\">For discrete data, you can choose to plot it with a Python\u00a0heatmap.<\/span><\/p>\n<h4><strong>i. Normalizing a column<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">So, consider the following piece of code-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; df=pd.DataFrame(np.random.randn(7,7)*4+3)\r\n&gt;&gt;&gt; df[1]=df[1]+37\r\n&gt;&gt;&gt; sn.heatmap(df,cmap='plasma')<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x09E1FC90&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22611\" style=\"width: 523px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22611\" class=\"wp-image-22611 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization1.png\" alt=\"Python Heatmap\" width=\"513\" height=\"424\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization1.png 513w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization1-150x124.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization1-300x248.png 300w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/a><p id=\"caption-attachment-22611\" class=\"wp-caption-text\">Normalizing a column in a heatmap in Python<\/p><\/div>\n<p><span style=\"font-weight: 400\">Now, in this plot, <\/span><i><span style=\"font-weight: 400\">1<\/span><\/i><span style=\"font-weight: 400\"> has considerably higher values. To get around this, we normalize it.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; df_norm=(df-df.mean())\/df.std()\r\n&gt;&gt;&gt; sn.heatmap(df_norm,cmap='plasma')<\/pre>\n<p><strong>&lt;matplotlib.axes._subplots.AxesSubplot object at 0x07EDEDD0&gt;<\/strong><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-matplotlib-tutorial\/\" target=\"_blank\" rel=\"noopener\">Do you know about Python Matplotlib<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22612\" style=\"width: 541px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22612\" class=\"wp-image-22612 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization2.png\" alt=\"Python Heatmap\" width=\"531\" height=\"428\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization2.png 531w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization2-150x121.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/normalization2-300x242.png 300w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/a><p id=\"caption-attachment-22612\" class=\"wp-caption-text\">Normalizing a column in heatmap Python<\/p><\/div>\n<h3>How to Create a Word Cloud in Python?<\/h3>\n<p><span style=\"font-weight: 400\">A word cloud in Python visually represents text data. Also called a tag cloud, it uses different font sizes and colors to highlight the importance of each word. This way, the most prominent terms will come across to the user. We will use the Word Cloud library here.<\/span><\/p>\n<p><strong>They are important because:<\/strong><\/p>\n<ul>\n<li>It lets you understand what is the topic of discussion in large text data easily.<\/li>\n<li>It helps you in identifying important words easily.<\/li>\n<li>It can show the common words used in the text quickly.<\/li>\n<\/ul>\n<h4><strong>a. A simple Word Cloud Python Example<\/strong><\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from wordcloud import WordCloud\r\n&gt;&gt;&gt; text=(\"Python Python Python C Java JavaScript jQuery jQuery R Python Python SQL HTML Lisp Java Ruby jQuery Python Python Django Scala Python JavaScript jQuery\")\r\n&gt;&gt;&gt; wordcloud=WordCloud(width=500,height=500,margin=1).generate(text)\r\n&gt;&gt;&gt; plt.imshow(wordcloud,interpolation='bilinear')<\/pre>\n<p><strong>&lt;matplotlib.image.AxesImage object at 0x09D1CC50&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.axis('off')<\/pre>\n<p><strong>(-0.5, 499.5, 499.5, -0.5)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.margins(x=0,y=0)\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22613\" style=\"width: 381px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/wordcloud.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22613\" class=\"wp-image-22613 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/wordcloud.png\" alt=\"Python Heatmap\" width=\"371\" height=\"370\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/wordcloud.png 371w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/wordcloud-150x150.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/wordcloud-300x300.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/wordcloud-100x100.png 100w\" sizes=\"auto, (max-width: 371px) 100vw, 371px\" \/><\/a><p id=\"caption-attachment-22613\" class=\"wp-caption-text\">Word Cloud Python Example<\/p><\/div>\n<h4>b. Setting the font size<\/h4>\n<p><span style=\"font-weight: 400\">Now, you can set a maximum and minimum font size for your Word cloud Python.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; wordcloud=WordCloud(width=500,height=500,max_font_size=30, min_font_size=10,margin=1).generate(text)\r\n&gt;&gt;&gt; plt.imshow(wordcloud,interpolation='bilinear')<\/pre>\n<p><strong>&lt;matplotlib.image.AxesImage object at 0x0832CB70&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.axis('off')<\/pre>\n<p><strong><span style=\"font-family: Verdana, Geneva, sans-serif\">(-0.5, 499.5, 499.5, -0.5)<\/span><\/strong><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/data-wrangling-with-python\/\">Learn Aggregation and Data Wrangling with Python<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.margins(x=0,y=0)\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22614\" style=\"width: 381px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22614\" class=\"wp-image-22614 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font.png\" alt=\"Python Heatmap\" width=\"371\" height=\"368\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font.png 371w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-150x150.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-300x298.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-100x100.png 100w\" sizes=\"auto, (max-width: 371px) 100vw, 371px\" \/><\/a><p id=\"caption-attachment-22614\" class=\"wp-caption-text\">Setting the font size in Word Cloud Python<\/p><\/div>\n<h4><strong>c. Limit the number of words<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">Now, let\u2019s see what happens if we don\u2019t call the axis() and margins() methods.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; wordcloud=WordCloud(width=500,height=500,max_words=4,margin=1).generate(text)\r\n&gt;&gt;&gt; plt.imshow(wordcloud,interpolation='bilinear')<\/pre>\n<p><strong>&lt;matplotlib.image.AxesImage object at 0x07EDECD0&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22621\" style=\"width: 460px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/limit-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22621\" class=\"wp-image-22621 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/limit-1.png\" alt=\"Python Heatmap\" width=\"450\" height=\"425\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/limit-1.png 450w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/limit-1-150x142.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/limit-1-300x283.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/a><p id=\"caption-attachment-22621\" class=\"wp-caption-text\">Python Word cloud &#8211; Limit the number of words<\/p><\/div>\n<h4><strong>d. Exclude some words<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">Generally, it is possible to use only some words from the text.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; wordcloud=WordCloud(width=500,height=500,stopwords=['Java','Django']).generate(text)\r\n&gt;&gt;&gt; plt.imshow(wordcloud,interpolation='bilinear')<\/pre>\n<p><strong>&lt;matplotlib.image.AxesImage object at 0x09E14030&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.axis('off')<\/pre>\n<p><strong>(-0.5, 499.5, 499.5, -0.5)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.margins(x=0,y=0)\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22615\" style=\"width: 380px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/exclude.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22615\" class=\"wp-image-22615 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/exclude.png\" alt=\"Python Heatmap\" width=\"370\" height=\"367\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/exclude.png 370w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/exclude-150x150.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/exclude-300x298.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/exclude-100x100.png 100w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/a><p id=\"caption-attachment-22615\" class=\"wp-caption-text\">Python Word cloud &#8211; Exclude some words<\/p><\/div>\n<h4>e. Change the background<\/h4>\n<p><span style=\"font-weight: 400\">Now, you can set the background to a certain color.<\/span><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-django-tutorial\/\">Want to learn about Python Django<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; wordcloud=WordCloud(height=500,width=500, background_color='darkturquoise').generate(text)\r\n&gt;&gt;&gt; plt.imshow(wordcloud,interpolation='bilinear')<\/pre>\n<p><strong>&lt;matplotlib.image.AxesImage object at 0x079B7190&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.axis('off') <span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0<\/span><\/pre>\n<p><strong>(-0.5, 499.5, 499.5, -0.5)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.margins(x=0,y=0)\r\n&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22622\" style=\"width: 380px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/background.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22622\" class=\"wp-image-22622 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/background.png\" alt=\"Python Heatmap\" width=\"370\" height=\"369\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/background.png 370w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/background-150x150.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/background-300x300.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/background-100x100.png 100w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/a><p id=\"caption-attachment-22622\" class=\"wp-caption-text\">Change the background in Word cloud Python<\/p><\/div>\n<h4><strong>f. Setting word color<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">Now, how about changing the color of words?<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; wordcloud=WordCloud(height=500,width=500,background_color='white', colormap='plasma').generate(text)\r\n&gt;&gt;&gt; plt.imshow(wordcloud,interpolation='bilinear')<\/pre>\n<p><strong>&lt;matplotlib.image.AxesImage object at 0x080AA830&gt;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.axis('off')<\/pre>\n<p><strong>(-0.5, 499.5, 499.5, -0.5)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22623\" style=\"width: 423px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/word-color-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22623\" class=\"wp-image-22623 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/word-color-1.png\" alt=\"Python Heatmap\" width=\"413\" height=\"413\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/word-color-1.png 413w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/word-color-1-150x150.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/word-color-1-300x300.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/word-color-1-100x100.png 100w\" sizes=\"auto, (max-width: 413px) 100vw, 413px\" \/><\/a><p id=\"caption-attachment-22623\" class=\"wp-caption-text\">Setting word color in Python Word Cloud<\/p><\/div>\n<h4><strong>g. Shaping a word cloud<\/strong><\/h4>\n<p><span style=\"font-weight: 400\">Now, it is possible to set a Python word cloud for a custom shape. Let\u2019s use a diamond:<\/span><\/p>\n<div id=\"attachment_22624\" style=\"width: 499px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22624\" class=\"wp-image-22624 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-2.png\" alt=\"Python Heatmap\" width=\"489\" height=\"439\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-2.png 489w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-2-150x135.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-2-300x269.png 300w\" sizes=\"auto, (max-width: 489px) 100vw, 489px\" \/><\/a><p id=\"caption-attachment-22624\" class=\"wp-caption-text\">Shaping a word cloud Python<\/p><\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from PIL import Image\r\n&gt;&gt;&gt; mask=np.array(Image.open('diamond.png'))\r\n&gt;&gt;&gt; wordcloud=WordCloud(mask=mask).generate(text)\r\n&gt;&gt;&gt; plt.imshow(wordcloud)<\/pre>\n<p><strong>&lt;matplotlib.image.AxesImage object at 0x07852630&gt;<\/strong><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-data-file-formats\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s explore Python data File formats<\/a><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.axis('off')<\/pre>\n<p><strong>(-0.5, 488.5, 438.5, -0.5)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; plt.show()<\/pre>\n<div id=\"attachment_22626\" style=\"width: 422px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22626\" class=\"wp-image-22626 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-1.png\" alt=\"Python Heatmap\" width=\"412\" height=\"368\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-1.png 412w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-1-150x134.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/diamond-1-300x268.png 300w\" sizes=\"auto, (max-width: 412px) 100vw, 412px\" \/><\/a><p id=\"caption-attachment-22626\" class=\"wp-caption-text\">Shaping a word cloud Python<\/p><\/div>\n<p>So, this was all in Python Heatmap. Hope you like our explanation of Word Cloud Python.<\/p>\n<h3><strong>Conclusion<\/strong><\/h3>\n<p>Heatmaps are effective in exploring categorical data, such as showing click-through rates across multiple pages and user segments. They are visually appealing and easy to interpret for both technical and non-technical audiences. When used properly, heatmaps can highlight valuable insights that might be missed in raw tables or summary statistics.<\/p>\n<p><span style=\"font-weight: 400\">Hence, in this Python Heatmap tutorial, we discussed what a heat map is and how to create a Python Heatmap. Moreover, we discussed Word Cloud Python. In this, we saw what a Word cloud is and how to make a Word Cloud. Also, we saw the Word Cloud Python Example. So this is how we create heat maps and word clouds in Python. For this, we used the libraries matplotlib and word cloud in this tutorial. Still, if any doubt regarding Python Heatmap, ask in the comments tab.<\/span><br \/>\n<strong>See also &#8211;<\/strong><br \/>\n<strong><a href=\"https:\/\/data-flair.training\/blogs\/python-charts\/\">Python Charts<\/a><\/strong><br \/>\n<a href=\"https:\/\/www.python.org\/\"><strong>For reference<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Next in our series of graphs and plots with Python is Python Heatmaps and Word Cloud. Moreover, we will see what a Python Heatmap and a Python Word Cloud are. Also, we will discuss&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":22642,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[5608,5609,5610,5611,6029,6038,6250,10579,10580,15747,16037,16219,16220,16221],"class_list":["post-22567","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-heatmap","tag-heatmap-examples","tag-heatmap-python","tag-heatmap-python-pandas","tag-how-to-create-a-heatmap","tag-how-to-create-a-word-cloud","tag-how-to-make-a-word-cloud","tag-python-heatmap","tag-python-heatmap-from-matrix","tag-what-is-heat-map","tag-what-is-word-cloud","tag-word-cloud","tag-word-cloud-python","tag-word-cloud-python-example"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Heatmap | Word Cloud Python with Example - DataFlair<\/title>\n<meta name=\"description\" content=\"A Heatmap in Python is a way of representing data as a matrix of values. Let&#039;s see what a Python Heatmap and a Python Word Cloud are.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Heatmap | Word Cloud Python with Example - DataFlair\" \/>\n<meta property=\"og:description\" content=\"A Heatmap in Python is a way of representing data as a matrix of values. Let&#039;s see what a Python Heatmap and a Python Word Cloud are.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-25T04:00:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-29T10:37:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Heatmap-Word-Cloud-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Heatmap | Word Cloud Python with Example - DataFlair","description":"A Heatmap in Python is a way of representing data as a matrix of values. Let's see what a Python Heatmap and a Python Word Cloud are.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/","og_locale":"en_US","og_type":"article","og_title":"Python Heatmap | Word Cloud Python with Example - DataFlair","og_description":"A Heatmap in Python is a way of representing data as a matrix of values. Let's see what a Python Heatmap and a Python Word Cloud are.","og_url":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-07-25T04:00:54+00:00","article_modified_time":"2026-04-29T10:37:00+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Heatmap-Word-Cloud-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Heatmap | Word Cloud Python with Example","datePublished":"2018-07-25T04:00:54+00:00","dateModified":"2026-04-29T10:37:00+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/"},"wordCount":1286,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Heatmap-Word-Cloud-01.jpg","keywords":["heatmap","heatmap examples","heatmap Python","Heatmap Python Pandas","how to create a Heatmap","how to create a word cloud","how to make a word cloud","Python Heatmap","Python Heatmap from matrix","what is Heat map","what is word cloud","word cloud","word cloud python","word cloud Python example"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/","url":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/","name":"Python Heatmap | Word Cloud Python with Example - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Heatmap-Word-Cloud-01.jpg","datePublished":"2018-07-25T04:00:54+00:00","dateModified":"2026-04-29T10:37:00+00:00","description":"A Heatmap in Python is a way of representing data as a matrix of values. Let's see what a Python Heatmap and a Python Word Cloud are.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Heatmap-Word-Cloud-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Heatmap-Word-Cloud-01.jpg","width":1200,"height":628,"caption":"Python Heatmap | Word Cloud Python - Example"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-heatmap-word-cloud\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Heatmap | Word Cloud Python with Example"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/22567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=22567"}],"version-history":[{"count":8,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/22567\/revisions"}],"predecessor-version":[{"id":148118,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/22567\/revisions\/148118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/22642"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=22567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=22567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=22567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}