.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plots/colors.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_plots_colors.py: .. _exa-colors: Colors ====== In general, colors for categorial variables are set as ``{cell: color}`` dictionaries. For factors, cells are strings, and for interactions they are tuples of strings. Colors can be set to any color understood by matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 23-40 .. code-block:: Python # sphinx_gallery_thumbnail_number = 3 from eelbrain import * ds = datasets.get_uv() colors = {'a1': (1, 0, 0), 'a2': (0, 0, 1)} p = plot.Barplot('fltvar', 'A', data=ds, w=2, colors=colors) colors = { ('a1', 'b1'): 'red', ('a1', 'b2'): (1, 1, 0), ('a2', 'b1'): (0, 0, 1), ('a2', 'b2'): (0, 1, 1), } p = plot.Barplot('fltvar - 0.5', 'A % B', data=ds, w=2, colors=colors) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_001.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_002.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 41-44 Unambiguous colors ^^^^^^^^^^^^^^^^^^ Eelbrain also comes with utilities to quickly generate such color dictionaries. `Unambiguous colors `_ are colors for up to 8 categories that are universally distinguishable. .. GENERATED FROM PYTHON SOURCE LINES 44-56 .. code-block:: Python # add a Factor with more categories ds['AB'] = ds.eval('A%B').as_factor() colors = plot.colors_for_oneway(ds['AB'].cells, unambiguous=True) p = plot.Barplot('fltvar - 0.5', 'AB', data=ds, w=2, xticks=False, colors=colors) p_colors = plot.ColorList(colors) colors = plot.colors_for_oneway(ds['AB'].cells, unambiguous=[2, 5, 3, 6]) p = plot.Barplot('fltvar - 0.5', 'AB', data=ds, w=2, xticks=False, colors=colors) p_colors = plot.ColorList(colors) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_003.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_004.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_004.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_005.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_005.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_006.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_006.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 57-60 Hue-based colors ^^^^^^^^^^^^^^^^ Colors can also be generated based on a color wheel. .. GENERATED FROM PYTHON SOURCE LINES 60-73 .. code-block:: Python cells = 'abc' colors = plot.colors_for_oneway(cells) p = plot.ColorList(colors) cells = 'abc' colors = plot.colors_for_oneway(cells, hue_start=0.3) p = plot.ColorList(colors) cells = 'abcdefgh' colors = plot.colors_for_oneway(cells) p = plot.ColorList(colors) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_007.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_007.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_008.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_008.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_009.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_009.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 74-75 Hue and lightness can be used to distinguish two factors in an interaction. .. GENERATED FROM PYTHON SOURCE LINES 75-90 .. code-block:: Python cells_a = ('a', 'b') cells_b = ('1', '2') colors = plot.colors_for_twoway(cells_a, cells_b) p = plot.ColorGrid(cells_a, cells_b, colors, h=1, w=1) cells_a = ('a', 'b') cells_b = ('1', '2', '3') colors = plot.colors_for_twoway(cells_a, cells_b) p = plot.ColorGrid(cells_a, cells_b, colors, h=1, w=1) cells_a = ('a', 'b', 'c') cells_b = ('1', '2') colors = plot.colors_for_twoway(cells_a, cells_b, hue_start=0.3) p = plot.ColorGrid(cells_a, cells_b, colors, h=1, w=1) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_010.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_010.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_011.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_011.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/plots/images/sphx_glr_colors_012.png :alt: colors :srcset: /auto_examples/plots/images/sphx_glr_colors_012.png :class: sphx-glr-multi-img .. _sphx_glr_download_auto_examples_plots_colors.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: colors.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: colors.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: colors.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_