""" Cell color ========== """ # %% # Cells are colored with the `colors` argument. # %% # Color cells with numerical values. import plotly import ptvis elements = list(ptvis.Element) atomic_numbers = [element.value for element in elements] fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells(fig, elements, colors=atomic_numbers) plotly.io.show(fig) # %% # Color cells with non-numerical values. import plotly import ptvis elements = list(ptvis.Element) initials = [element.name[0] for element in elements] fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells(fig, elements, colors=initials) plotly.io.show(fig) # %% # Conversion from values to colors # -------------------------------- # %% # By default, a conversion from the `colors` argument to colors is defined by # the :class:`ptvis.color.ContinuousColorConversion` class for numerical values # and by the :class:`ptvis.color.CategoricalColorConversion` class for # non-numerical values. The conversion can be changed by the `color_conversion` # argument. For example, numerical values can be treated as categories. import plotly import ptvis.color elements = list(ptvis.Element) atomic_numbers = [element.value for element in elements] fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells( fig, elements, colors=atomic_numbers, color_conversion=ptvis.color.CategoricalColorConversion(), ) plotly.io.show(fig) # %% # See the :doc:`tutorial on the color conversion <../color_conversion/index>` # for more details. # %% # Color guide # ----------- # %% # A color guide is shown by giving its attributes to the `color_guide` # argument. The kind of color guide is determined by the color conversion. # %% # A color scale is shown for a conversion from numerical values. Attributes of # the :class:`plotly.graph_objects.scatter.marker.ColorBar` are valid. import plotly import ptvis elements = list(ptvis.Element) atomic_numbers = [element.value for element in elements] fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells( fig, elements, colors=atomic_numbers, color_guide={ "outlinewidth": 0, "ticks": "outside", }, ) plotly.io.show(fig) # %% # A legend is shown for a conversion from categories. Attributes of the # :class:`plotly.graph_objects.scatter.Marker` are valid. import plotly import ptvis elements = list(ptvis.Element) initials = [element.name[0] for element in elements] fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells( fig, elements, colors=initials, color_guide={ "size": 12, "symbol": "square", }, ) plotly.io.show(fig)