{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Sector color\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sectors are colored with the `colors` argument.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Color sectors with numerical values.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import plotly\nimport ptvis\n\n\nelements = list(ptvis.Element) * 2\natomic_numbers = (\n [element.value for element in ptvis.Element]\n + [element.value + 50 for element in ptvis.Element]\n)\n\nfig = plotly.graph_objects.Figure()\nptvis.attach_pie_cells(fig, elements, colors=atomic_numbers)\n\nplotly.io.show(fig)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Color sectors with non-numerical values.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import plotly\nimport ptvis\n\n\nelements = list(ptvis.Element) * 2\ninitials = (\n [element.name[0] for element in ptvis.Element]\n + [element.name[0].lower() for element in ptvis.Element]\n)\n\nfig = plotly.graph_objects.Figure()\nptvis.attach_pie_cells(fig, elements, colors=initials)\n\nplotly.io.show(fig)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conversion from values to colors\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, a conversion from the `colors` argument to colors is defined by\nthe :class:`ptvis.color.ContinuousColorConversion` class for numerical values\nand by the :class:`ptvis.color.CategoricalColorConversion` class for\nnon-numerical values. The conversion can be changed by the `color_conversion`\nargument. For example, numerical values can be treated as categories.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import plotly\nimport ptvis.color\n\n\nelements = list(ptvis.Element) * 2\natomic_numbers = (\n [element.value for element in ptvis.Element]\n + [element.value + 55 for element in ptvis.Element]\n)\n\nfig = plotly.graph_objects.Figure()\nptvis.attach_pie_cells(\n fig,\n elements,\n colors=atomic_numbers,\n color_conversion=ptvis.color.CategoricalColorConversion(),\n)\n\nplotly.io.show(fig)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "See the :doc:`tutorial on the color conversion <../color_conversion/index>`\nfor more details.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Color guide\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A color guide is shown by giving its attributes to the `color_guide`\nargument. The kind of color guide is determined by the color conversion.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A color scale is shown for a conversion from numerical values. Attributes of\nthe :class:`plotly.graph_objects.scatter.marker.ColorBar` are valid.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import plotly\nimport ptvis\n\n\nelements = list(ptvis.Element) * 2\natomic_numbers = (\n [element.value for element in ptvis.Element]\n + [element.value + 55 for element in ptvis.Element]\n)\n\nfig = plotly.graph_objects.Figure()\nptvis.attach_pie_cells(\n fig,\n elements,\n colors=atomic_numbers,\n color_guide={\n \"outlinewidth\": 0,\n \"ticks\": \"outside\",\n },\n)\n\nplotly.io.show(fig)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A legend is shown for a conversion from categories. Attributes of the\n:class:`plotly.graph_objects.scatter.Marker` are valid.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import plotly\nimport ptvis\n\n\nelements = list(ptvis.Element) * 2\ninitials = (\n [element.name[0] for element in ptvis.Element]\n + [element.name[0].lower() for element in ptvis.Element]\n)\n\nfig = plotly.graph_objects.Figure()\nptvis.attach_pie_cells(\n fig,\n elements,\n colors=initials,\n color_guide={\n \"size\": 12,\n \"symbol\": \"square\",\n },\n)\n\nplotly.io.show(fig)" ] } ], "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.13.3" } }, "nbformat": 4, "nbformat_minor": 0 }