{
  "id": 307525,
  "title": "How to do a cool Similarity Matrix in matplotlib",
  "url": "/competitions/happy-whale-and-dolphin/discussion/307525",
  "author_name": "",
  "post_date": "2022-02-14T15:33:36.270812300Z",
  "votes": 53,
  "comment_count": 5,
  "views": 0,
  "content": "<p>Hi!</p>\n<p>So, while working on this competition, I came across <a href=\"https://learnopencv.com/face-recognition-with-arcface/\" target=\"_blank\">this amazing article</a> and was absolutely mermerized about this particular graph:</p>\n<p><img src=\"https://i.imgur.com/gX48r2U.png\"></p>\n<p>…. and I immediately wanted to know how to do it. It is a <strong>matrix that shows the similarity percentage between multiple images</strong>.</p>\n<p>They had a tutorial too, but I wanted to find a very simple, straight forward way to create a plot like this.</p>\n<p>Long story short, if you ever happen to need to create subplots within matplotlib, but the number of rows, columns is dynamic, as well as the size of the plots, you could use these lines (<a href=\"https://www.kaggle.com/andradaolteanu/whales-dolphins-effnet-embedding-cos-distance\" target=\"_blank\">here is my notebook for full implementation</a>):</p>\n<p><img src=\"https://i.imgur.com/gKiuT6n.png\"></p>\n<p><strong>Quick Explanation of the parameters</strong>:</p>\n<ul>\n<li><code>shape=(n, n)</code> - this is the TOTAL shape of plot. In my case it had 6 total rows and columns.</li>\n<li><code>loc=(x, y)</code> - this is the speciffic location of the top left corner of the chart, where x and y are the coordinates.</li>\n<li><code>colspan=c</code> and <code>rowspan=r</code> - this is <em>how far</em> do you want your graph to strech. By default it is set to 1, but you could strech it as long/wide as you want (of course, never greater than n, which in my case was 6).</li>\n</ul>\n<p>… and then you will get this:</p>\n<p><img src=\"https://i.imgur.com/kb3DYNc.png\"></p>\n<p>Hope this helps some of you! Cheers 🐳🐬</p>",
  "messages": [
    {
      "id": "1689925",
      "postDate": "02/14/2022 15:33:36",
      "content": "<p>Hi!</p>\n<p>So, while working on this competition, I came across <a href=\"https://learnopencv.com/face-recognition-with-arcface/\" target=\"_blank\">this amazing article</a> and was absolutely mermerized about this particular graph:</p>\n<p><img src=\"https://i.imgur.com/gX48r2U.png\"></p>\n<p>…. and I immediately wanted to know how to do it. It is a <strong>matrix that shows the similarity percentage between multiple images</strong>.</p>\n<p>They had a tutorial too, but I wanted to find a very simple, straight forward way to create a plot like this.</p>\n<p>Long story short, if you ever happen to need to create subplots within matplotlib, but the number of rows, columns is dynamic, as well as the size of the plots, you could use these lines (<a href=\"https://www.kaggle.com/andradaolteanu/whales-dolphins-effnet-embedding-cos-distance\" target=\"_blank\">here is my notebook for full implementation</a>):</p>\n<p><img src=\"https://i.imgur.com/gKiuT6n.png\"></p>\n<p><strong>Quick Explanation of the parameters</strong>:</p>\n<ul>\n<li><code>shape=(n, n)</code> - this is the TOTAL shape of plot. In my case it had 6 total rows and columns.</li>\n<li><code>loc=(x, y)</code> - this is the speciffic location of the top left corner of the chart, where x and y are the coordinates.</li>\n<li><code>colspan=c</code> and <code>rowspan=r</code> - this is <em>how far</em> do you want your graph to strech. By default it is set to 1, but you could strech it as long/wide as you want (of course, never greater than n, which in my case was 6).</li>\n</ul>\n<p>… and then you will get this:</p>\n<p><img src=\"https://i.imgur.com/kb3DYNc.png\"></p>\n<p>Hope this helps some of you! Cheers 🐳🐬</p>",
      "rawMarkdown": "Hi!\n\nSo, while working on this competition, I came across [this amazing article](https://learnopencv.com/face-recognition-with-arcface/) and was absolutely mermerized about this particular graph:\n\n<center><img src=\"https://i.imgur.com/gX48r2U.png\" width=600></center>\n\n.... and I immediately wanted to know how to do it. It is a **matrix that shows the similarity percentage between multiple images**.\n\nThey had a tutorial too, but I wanted to find a very simple, straight forward way to create a plot like this.\n\nLong story short, if you ever happen to need to create subplots within matplotlib, but the number of rows, columns is dynamic, as well as the size of the plots, you could use these lines ([here is my notebook for full implementation](https://www.kaggle.com/andradaolteanu/whales-dolphins-effnet-embedding-cos-distance)):\n\n<center><img src=\"https://i.imgur.com/gKiuT6n.png\" width=800></center>\n\n**Quick Explanation of the parameters**:\n* `shape=(n, n)` - this is the TOTAL shape of plot. In my case it had 6 total rows and columns.\n* `loc=(x, y)` - this is the speciffic location of the top left corner of the chart, where x and y are the coordinates.\n* `colspan=c` and `rowspan=r` - this is *how far* do you want your graph to strech. By default it is set to 1, but you could strech it as long/wide as you want (of course, never greater than n, which in my case was 6).\n\n... and then you will get this:\n\n<center><img src=\"https://i.imgur.com/kb3DYNc.png\" width=600></center>\n\nHope this helps some of you! Cheers 🐳🐬",
      "votes": null
    },
    {
      "id": "1689953",
      "postDate": "02/14/2022 15:52:30",
      "content": "<p>this is a cool way </p>",
      "rawMarkdown": "this is a cool way",
      "votes": null
    },
    {
      "id": "1692548",
      "postDate": "02/16/2022 05:34:19",
      "content": "<p>This is awesome! Thanks for sharing.</p>",
      "rawMarkdown": "This is awesome! Thanks for sharing.",
      "votes": null
    },
    {
      "id": "1696399",
      "postDate": "02/18/2022 20:01:20",
      "content": "<p>It is so beautiful! Thank you for sharing with us the article and code, <a href=\"https://www.kaggle.com/andradaolteanu\" target=\"_blank\">@andradaolteanu</a>! </p>",
      "rawMarkdown": "It is so beautiful! Thank you for sharing with us the article and code, @andradaolteanu!",
      "votes": null
    },
    {
      "id": "1697380",
      "postDate": "02/19/2022 15:27:36",
      "content": "<p>Thank you for sharing this! It's really helpful</p>",
      "rawMarkdown": "Thank you for sharing this! It's really helpful",
      "votes": null
    },
    {
      "id": "2015501",
      "postDate": "11/03/2022 10:28:07",
      "content": "<p>Thanks for sharing!</p>",
      "rawMarkdown": "Thanks for sharing!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1689953,
      "author_name": "heyrobin",
      "author_url": "",
      "post_date": "02/14/2022 15:52:30",
      "content": "<p>this is a cool way </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1692548,
      "author_name": "utcarshagrawal",
      "author_url": "",
      "post_date": "02/16/2022 05:34:19",
      "content": "<p>This is awesome! Thanks for sharing.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1696399,
      "author_name": "vad13irt",
      "author_url": "",
      "post_date": "02/18/2022 20:01:20",
      "content": "<p>It is so beautiful! Thank you for sharing with us the article and code, <a href=\"https://www.kaggle.com/andradaolteanu\" target=\"_blank\">@andradaolteanu</a>! </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1697380,
      "author_name": "fadillarizalul",
      "author_url": "",
      "post_date": "02/19/2022 15:27:36",
      "content": "<p>Thank you for sharing this! It's really helpful</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 2015501,
      "author_name": "ashukm",
      "author_url": "",
      "post_date": "11/03/2022 10:28:07",
      "content": "<p>Thanks for sharing!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1689925": "Hi!\n\nSo, while working on this competition, I came across [this amazing article](https://learnopencv.com/face-recognition-with-arcface/) and was absolutely mermerized about this particular graph:\n\n<center><img src=\"https://i.imgur.com/gX48r2U.png\" width=600></center>\n\n.... and I immediately wanted to know how to do it. It is a **matrix that shows the similarity percentage between multiple images**.\n\nThey had a tutorial too, but I wanted to find a very simple, straight forward way to create a plot like this.\n\nLong story short, if you ever happen to need to create subplots within matplotlib, but the number of rows, columns is dynamic, as well as the size of the plots, you could use these lines ([here is my notebook for full implementation](https://www.kaggle.com/andradaolteanu/whales-dolphins-effnet-embedding-cos-distance)):\n\n<center><img src=\"https://i.imgur.com/gKiuT6n.png\" width=800></center>\n\n**Quick Explanation of the parameters**:\n* `shape=(n, n)` - this is the TOTAL shape of plot. In my case it had 6 total rows and columns.\n* `loc=(x, y)` - this is the speciffic location of the top left corner of the chart, where x and y are the coordinates.\n* `colspan=c` and `rowspan=r` - this is *how far* do you want your graph to strech. By default it is set to 1, but you could strech it as long/wide as you want (of course, never greater than n, which in my case was 6).\n\n... and then you will get this:\n\n<center><img src=\"https://i.imgur.com/kb3DYNc.png\" width=600></center>\n\nHope this helps some of you! Cheers 🐳🐬",
    "1689953": "this is a cool way",
    "1692548": "This is awesome! Thanks for sharing.",
    "1696399": "It is so beautiful! Thank you for sharing with us the article and code, @andradaolteanu!",
    "1697380": "Thank you for sharing this! It's really helpful",
    "2015501": "Thanks for sharing!"
  },
  "source": "meta"
}