{
  "id": 341898,
  "title": "🎨 How to make a Custom Colormap for matplotlib graphs",
  "url": "/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/341898",
  "author_name": "Andrada",
  "post_date": "2022-08-04T17:13:30.261000",
  "votes": 21,
  "comment_count": 5,
  "views": 0,
  "content": "<p>Ok so I have been searching a bunch for a way to create a custom map and what is the <strong>easiest</strong> and <strong>quickest</strong> way to do so.</p>\n<p>There are many <a href=\"https://matplotlib.org/stable/tutorials/colors/colormaps.html\" target=\"_blank\">premade colormaps for matplotlib</a> but I usually create my own <em>categorical</em> color scheme for each competition.</p>\n<p>Therefore, I wanted to use this personalized palette in my graphs too (below I've a picture with the palette I am using for this competition):<br>\n<img src=\"https://i.imgur.com/Nu0jrWL.png\"></p>\n<p>So, here's how I do this quickly.</p>\n<h4>1. The initial graph</h4>\n<p>By default, the below scatterplot looks like this:</p>\n<pre><code>sns.scatterplot(data=data, x=\"count\", y=\"y\", size=\"count\", alpha=0.65, sizes=(500, 2000),\n               hue=\"count\")\n</code></pre>\n<p><img src=\"https://i.imgur.com/Yrw5m7t.png\"></p>\n<h4>2. Create Customized Map</h4>\n<p>Next step is to create a <code>CMAP1</code> that's personalized with <code>my_colors</code>:</p>\n<pre><code>from matplotlib.colors import ListedColormap\n\nmy_colors = [\"#5EAFD9\", \"#449DD1\", \"#3977BB\", \n             \"#2D51A5\", \"#5C4C8F\", \"#8B4679\",\n             \"#C53D4C\", \"#E23836\", \"#FF4633\", \"#FF5746\"]\nCMAP1 = ListedColormap(my_colors)\n</code></pre>\n<h4>3. Change the final graph</h4>\n<pre><code>sns.scatterplot(data=data, x=\"count\", y=\"y\", size=\"count\", alpha=0.65, sizes=(500, 2000),\n               hue=\"count\", palette=CMAP1)\n</code></pre>\n<p><img src=\"https://i.imgur.com/wgUE3hG.png\"></p>\n<p>Hope this helps anyone interested 😊 Cheers!</p>",
  "messages": [
    {
      "id": 1884831,
      "postDate": "2022-08-04T17:13:30.260Z",
      "content": "<p>Ok so I have been searching a bunch for a way to create a custom map and what is the <strong>easiest</strong> and <strong>quickest</strong> way to do so.</p>\n<p>There are many <a href=\"https://matplotlib.org/stable/tutorials/colors/colormaps.html\" target=\"_blank\">premade colormaps for matplotlib</a> but I usually create my own <em>categorical</em> color scheme for each competition.</p>\n<p>Therefore, I wanted to use this personalized palette in my graphs too (below I've a picture with the palette I am using for this competition):<br>\n<img src=\"https://i.imgur.com/Nu0jrWL.png\"></p>\n<p>So, here's how I do this quickly.</p>\n<h4>1. The initial graph</h4>\n<p>By default, the below scatterplot looks like this:</p>\n<pre><code>sns.scatterplot(data=data, x=\"count\", y=\"y\", size=\"count\", alpha=0.65, sizes=(500, 2000),\n               hue=\"count\")\n</code></pre>\n<p><img src=\"https://i.imgur.com/Yrw5m7t.png\"></p>\n<h4>2. Create Customized Map</h4>\n<p>Next step is to create a <code>CMAP1</code> that's personalized with <code>my_colors</code>:</p>\n<pre><code>from matplotlib.colors import ListedColormap\n\nmy_colors = [\"#5EAFD9\", \"#449DD1\", \"#3977BB\", \n             \"#2D51A5\", \"#5C4C8F\", \"#8B4679\",\n             \"#C53D4C\", \"#E23836\", \"#FF4633\", \"#FF5746\"]\nCMAP1 = ListedColormap(my_colors)\n</code></pre>\n<h4>3. Change the final graph</h4>\n<pre><code>sns.scatterplot(data=data, x=\"count\", y=\"y\", size=\"count\", alpha=0.65, sizes=(500, 2000),\n               hue=\"count\", palette=CMAP1)\n</code></pre>\n<p><img src=\"https://i.imgur.com/wgUE3hG.png\"></p>\n<p>Hope this helps anyone interested 😊 Cheers!</p>",
      "rawMarkdown": "Ok so I have been searching a bunch for a way to create a custom map and what is the **easiest** and **quickest** way to do so.\n\nThere are many [premade colormaps for matplotlib](https://matplotlib.org/stable/tutorials/colors/colormaps.html) but I usually create my own *categorical* color scheme for each competition.\n\nTherefore, I wanted to use this personalized palette in my graphs too (below I've a picture with the palette I am using for this competition):\n<img src=\"https://i.imgur.com/Nu0jrWL.png\">\n\nSo, here's how I do this quickly.\n\n#### 1. The initial graph\n\nBy default, the below scatterplot looks like this:\n\n```\nsns.scatterplot(data=data, x=\"count\", y=\"y\", size=\"count\", alpha=0.65, sizes=(500, 2000),\n               hue=\"count\")\n```\n<img src=\"https://i.imgur.com/Yrw5m7t.png\">\n\n#### 2. Create Customized Map\n\nNext step is to create a `CMAP1` that's personalized with `my_colors`:\n\n```\nfrom matplotlib.colors import ListedColormap\n\nmy_colors = [\"#5EAFD9\", \"#449DD1\", \"#3977BB\", \n             \"#2D51A5\", \"#5C4C8F\", \"#8B4679\",\n             \"#C53D4C\", \"#E23836\", \"#FF4633\", \"#FF5746\"]\nCMAP1 = ListedColormap(my_colors)\n```\n\n#### 3. Change the final graph\n\n```\nsns.scatterplot(data=data, x=\"count\", y=\"y\", size=\"count\", alpha=0.65, sizes=(500, 2000),\n               hue=\"count\", palette=CMAP1)\n```\n<img src=\"https://i.imgur.com/wgUE3hG.png\">\n\nHope this helps anyone interested 😊 Cheers!",
      "votes": 20
    },
    {
      "id": 1885281,
      "postDate": "2022-08-05T04:13:35.177Z",
      "content": "<p>very useful information ! Thank you for sharing !</p>",
      "rawMarkdown": "very useful information ! Thank you for sharing !"
    },
    {
      "id": 1884893,
      "postDate": "2022-08-04T18:09:44.380Z",
      "content": "<p>This is quite useful to make one's work look great and perhaps elicit key features also! Great work!! Bookmarked!!</p>",
      "rawMarkdown": "This is quite useful to make one's work look great and perhaps elicit key features also! Great work!! Bookmarked!!"
    },
    {
      "id": 1890978,
      "postDate": "2022-08-09T06:52:58.123Z",
      "content": "<p>You always do something unique <a href=\"https://www.kaggle.com/andradaolteanu\" target=\"_blank\">@andradaolteanu</a> </p>",
      "rawMarkdown": "You always do something unique @andradaolteanu "
    },
    {
      "id": 2042201,
      "postDate": "2022-11-24T14:02:59.350Z",
      "content": "<p>This is gold! Thank you!</p>",
      "rawMarkdown": "This is gold! Thank you!"
    },
    {
      "id": 1888833,
      "postDate": "2022-08-07T19:49:30.833Z",
      "content": "<p>that's helpful, thanks!</p>",
      "rawMarkdown": "that's helpful, thanks!"
    }
  ],
  "comments": [
    {
      "id": 1885281,
      "author_name": "Arun Purakkatt",
      "author_url": "",
      "post_date": "2022-08-05T04:13:35.177000",
      "content": "<p>very useful information ! Thank you for sharing !</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1884893,
      "author_name": "Ravi Ramakrishnan",
      "author_url": "",
      "post_date": "2022-08-04T18:09:44.380000",
      "content": "<p>This is quite useful to make one's work look great and perhaps elicit key features also! Great work!! Bookmarked!!</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1890978,
      "author_name": "Abdullah Sangha",
      "author_url": "",
      "post_date": "2022-08-09T06:52:58.123000",
      "content": "<p>You always do something unique <a href=\"https://www.kaggle.com/andradaolteanu\" target=\"_blank\">@andradaolteanu</a> </p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 2042201,
      "author_name": "Leandro Destefani",
      "author_url": "",
      "post_date": "2022-11-24T14:02:59.350000",
      "content": "<p>This is gold! Thank you!</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1888833,
      "author_name": "Ahmed Yassin",
      "author_url": "",
      "post_date": "2022-08-07T19:49:30.833000",
      "content": "<p>that's helpful, thanks!</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1884831": "Ok so I have been searching a bunch for a way to create a custom map and what is the **easiest** and **quickest** way to do so.\n\nThere are many [premade colormaps for matplotlib](https://matplotlib.org/stable/tutorials/colors/colormaps.html) but I usually create my own *categorical* color scheme for each competition.\n\nTherefore, I wanted to use this personalized palette in my graphs too (below I've a picture with the palette I am using for this competition):\n<img src=\"https://i.imgur.com/Nu0jrWL.png\">\n\nSo, here's how I do this quickly.\n\n#### 1. The initial graph\n\nBy default, the below scatterplot looks like this:\n\n```\nsns.scatterplot(data=data, x=\"count\", y=\"y\", size=\"count\", alpha=0.65, sizes=(500, 2000),\n               hue=\"count\")\n```\n<img src=\"https://i.imgur.com/Yrw5m7t.png\">\n\n#### 2. Create Customized Map\n\nNext step is to create a `CMAP1` that's personalized with `my_colors`:\n\n```\nfrom matplotlib.colors import ListedColormap\n\nmy_colors = [\"#5EAFD9\", \"#449DD1\", \"#3977BB\", \n             \"#2D51A5\", \"#5C4C8F\", \"#8B4679\",\n             \"#C53D4C\", \"#E23836\", \"#FF4633\", \"#FF5746\"]\nCMAP1 = ListedColormap(my_colors)\n```\n\n#### 3. Change the final graph\n\n```\nsns.scatterplot(data=data, x=\"count\", y=\"y\", size=\"count\", alpha=0.65, sizes=(500, 2000),\n               hue=\"count\", palette=CMAP1)\n```\n<img src=\"https://i.imgur.com/wgUE3hG.png\">\n\nHope this helps anyone interested 😊 Cheers!",
    "1885281": "very useful information ! Thank you for sharing !",
    "1884893": "This is quite useful to make one's work look great and perhaps elicit key features also! Great work!! Bookmarked!!",
    "1890978": "You always do something unique @andradaolteanu ",
    "2042201": "This is gold! Thank you!",
    "1888833": "that's helpful, thanks!"
  }
}