.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/matplotlib/plot_main05_b_clustermap.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_matplotlib_plot_main05_b_clustermap.py: 05.b ``sns.clustermap`` with ``network.csv`` -------------------------------------------- Plot a matrix dataset as a hierarchically-clustered heatmap. .. note:: The hierarchical clustering has been deactivated. .. GENERATED FROM PYTHON SOURCE LINES 10-48 .. image-sg:: /_examples/matplotlib/images/sphx_glr_plot_main05_b_clustermap_001.png :alt: plot main05 b clustermap :srcset: /_examples/matplotlib/images/sphx_glr_plot_main05_b_clustermap_001.png :class: sphx-glr-single-img .. code-block:: default :lineno-start: 11 import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # Load dataset networks = sns.load_dataset("brain_networks", index_col=0, header=[0, 1, 2]) # Create variables network_labels = networks.columns.get_level_values("network") network_pal = sns.cubehelix_palette( network_labels.unique().size, light=.9, dark=.1, reverse=True, start=1, rot=-2) network_lut = dict(zip(map(str, network_labels.unique()), network_pal)) network_colors = pd.Series(network_labels).map(network_lut) # The side colors are drawn with a heatmap, which matplotlib thinks # of as quantitative data and thus there's not a straightforward way # to get a legend directly from it. Instead of that, we'll add an # invisible barplot with the right colors and labels, then add a # legend for that. g = sns.clustermap(networks.corr(), row_cluster=False, col_cluster=False, # turn-off clustering row_colors=network_colors, col_colors=network_colors, # add class labels linewidths=0, xticklabels=False, yticklabels=False) # improve visual wih many rows for label in network_labels.unique(): g.ax_col_dendrogram.bar(0, 0, color=network_lut[label], label=label, linewidth=0) # Move the colorbar to the empty space. g.ax_col_dendrogram.legend(loc="center", ncol=6) g.cax.set_position([.15, .2, .03, .45]) # Show plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.442 seconds) .. _sphx_glr_download__examples_matplotlib_plot_main05_b_clustermap.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_main05_b_clustermap.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_main05_b_clustermap.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_