.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_mouse_embryo.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_mouse_embryo.py: Mouse Embryo Map ================ This example shows how to enhance a mouse embryo map. .. GENERATED FROM PYTHON SOURCE LINES 10-12 Load dataset and prepare data ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 12-38 .. code-block:: Python import numpy as np from matplotlib.colors import LinearSegmentedColormap from legendkit import cat_legend import marsilea as ma embryo = ma.load_data('mouse_embryo') xmax = embryo['cell_x'].max() ymax = embryo['cell_y'].max() xstart, xend = -xmax*0.05, xmax*1.05 ystart, yend = -ymax*0.05, ymax*1.05 xrange = np.linspace(xstart, xend, 200) yrange = np.linspace(ystart, yend, 200) xmid = (xrange[1:] + xrange[:-1]) / 2 ymid = (yrange[1:] + yrange[:-1]) / 2 def get_xy_hist(ct): x = embryo[embryo['cell_type'] == ct]['cell_x'].to_numpy() y = embryo[embryo['cell_type'] == ct]['cell_y'].to_numpy() xhist, _ = np.histogram(x, bins=xrange) yhist, _ = np.histogram(y, bins=yrange) return xhist, yhist .. GENERATED FROM PYTHON SOURCE LINES 39-40 Here we have a predefined colormap for each cell type. .. GENERATED FROM PYTHON SOURCE LINES 40-102 .. code-block:: Python colormap = { 'Cavity': '#6d32e6', 'Brain': '#bf024f', 'Meninges': '#d147a3', 'Choroid plexus': '#b3a726', 'Cartilage primordium': '#103a14', 'Jaw and tooth': '#ef833a', 'Connective tissue': '#b38b5c', 'Epidermis': '#35586d', 'Lung primordium': '#3cb44b', 'Sympathetic nerve': '#dfdce0', 'Liver': '#bd3add', 'Mucosal epithelium': '#0bd3b1', 'GI tract': '#ff4374', 'Mesentery': '#b74c11', 'Dorsal root ganglion': '#036df4', 'Muscle': '#dd7936', 'Mesothelium': '#5c5ca6', 'Blood vessel': '#be9b72', 'Urogenital ridge': '#d3245a', 'Heart': '#03fff4', 'Pancreas': '#f062f9', 'Kidney': '#62cfe8', 'Ovary': '#c923b1' } width = 5 height = width * (yend - ystart) / (xend - xstart) b = ma.WhiteBoard(height=height, width=width) cell_types = ["Brain", "Cartilage primordium", "Liver", "Heart", "GI tract"] for n in cell_types: b.add_canvas("bottom", size=.2, pad=.1, name=f"{n}-x") b.add_canvas("right", size=.2, pad=.1, name=f"{n}-y") b.render() # Draw cell ax = b.get_main_ax() ax.scatter(embryo['cell_x'], embryo['cell_y'], s=1, c=embryo['colors']) ax.set_xlim(xstart, xend) ax.set_ylim(ystart, yend) ax.set_title("Mouse Embryo E12.5") ax.set_axis_off() colors = list(colormap.values()) labels = list(colormap.keys()) cat_legend(colors=colors, labels=labels, ax=ax, loc="out left center", fontsize=8) for n in cell_types: xh, yh = get_xy_hist(n) cmap = LinearSegmentedColormap.from_list(n, ["white", colormap[n]]) x_ax = b.get_ax(f"{n}-x") x_ax.pcolormesh(xh.reshape(1, -1), cmap=cmap) x_ax.set_axis_off() x_ax.text(0, .5, n, va="center", ha="right", transform=x_ax.transAxes) y_ax = b.get_ax(f"{n}-y") y_ax.pcolormesh(yh.reshape(-1, 1), cmap=cmap) y_ax.set_axis_off() y_ax.text(0.5, 0, n, va="top", ha="center", rotation=90, transform=y_ax.transAxes) .. image-sg:: /auto_examples/images/sphx_glr_plot_mouse_embryo_001.png :alt: Mouse Embryo E12.5 :srcset: /auto_examples/images/sphx_glr_plot_mouse_embryo_001.png, /auto_examples/images/sphx_glr_plot_mouse_embryo_001_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.582 seconds) .. _sphx_glr_download_auto_examples_plot_mouse_embryo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mouse_embryo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_mouse_embryo.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_