{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Drawing Region Adjacency Graphs (RAGs)\n\nThis example constructs a Region Adjacency Graph (RAG) and draws it with\nthe `rag_draw` method.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from skimage import data, segmentation\nfrom skimage import graph\nfrom matplotlib import pyplot as plt\n\n\nimg = data.coffee()\nlabels = segmentation.slic(img, compactness=30, n_segments=400, start_label=1)\ng = graph.rag_mean_color(img, labels)\n\nfig, ax = plt.subplots(nrows=2, sharex=True, sharey=True, figsize=(6, 8))\n\nax[0].set_title('RAG drawn with default settings')\nlc = graph.show_rag(labels, g, img, ax=ax[0])\n# specify the fraction of the plot area that will be used to draw the colorbar\nfig.colorbar(lc, fraction=0.03, ax=ax[0])\n\nax[1].set_title('RAG drawn with grayscale image and viridis colormap')\nlc = graph.show_rag(labels, g, img, img_cmap='gray', edge_cmap='viridis', ax=ax[1])\nfig.colorbar(lc, fraction=0.03, ax=ax[1])\n\nfor a in ax:\n    a.axis('off')\n\nplt.tight_layout()\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.12"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}