""" From numerical values to continuous colors ========================================== """ # %% # The :class:`ptvis.color.ContinuousColorConversion` class defines a conversion # from numerical values to continuous colors. import plotly import ptvis.color elements = list(ptvis.Element) values = list(range(len(elements))) fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells( fig, elements, colors=values, color_conversion=ptvis.color.ContinuousColorConversion(), ) plotly.io.show(fig) # %% # Defining a conversion with colors for evenly spaced levels # ---------------------------------------------------------- # %% # The `colors` argument determines colors at evenly spaced levels of a color # scale. import plotly import ptvis.color elements = list(ptvis.Element) values = list(range(len(elements))) fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells( fig, elements, colors=values, color_conversion=ptvis.color.ContinuousColorConversion( colors=["blue", "green", "red"], ), ) plotly.io.show(fig) # %% # Defining a conversion with colors at arbitrary levels # ----------------------------------------------------- # %% # The levels of the `colors` argument can be changed by the `levels` argument. # The arugment must be given in ascending order. import plotly import ptvis.color elements = list(ptvis.Element) values = list(range(len(elements))) fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells( fig, elements, colors=values, color_conversion=ptvis.color.ContinuousColorConversion( colors=["blue", "green", "red"], levels=[-1, -0.5, 1], ), ) plotly.io.show(fig) # %% # Clipping # -------- # %% # By default, the minimum and maximum values correspond with the lowest and # highest levels. Values corresponding with the lowest and highest levels can # be changed by the `value_min` and `value_max` arguments. Values out of range # are converted into colors of the lowest and highest levels. import plotly import ptvis.color elements = list(ptvis.Element) values = list(range(len(elements))) fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells( fig, elements, colors=values, color_conversion=ptvis.color.ContinuousColorConversion( colors=["blue", "green", "red"], value_min=30, value_max=60, ), ) plotly.io.show(fig) # %% # Colors for out-of-range values can be changed by the `lower_color` and # `higher_color` argument. import plotly import ptvis.color elements = list(ptvis.Element) values = list(range(len(elements))) fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells( fig, elements, colors=values, color_conversion=ptvis.color.ContinuousColorConversion( colors=["blue", "green", "red"], value_min=30, value_max=60, lower_color="black", higher_color="white", ), ) plotly.io.show(fig) # %% # Color for NaN # -------------- # %% # A color for NaN can be changed by the `na_color` argument. import plotly import ptvis.color elements = list(ptvis.Element) values = [i if i % 10 else float("nan") for i in range(len(elements))] fig = plotly.graph_objects.Figure() ptvis.attach_plain_cells( fig, elements, colors=values, color_conversion=ptvis.color.ContinuousColorConversion( colors=["blue", "green", "red"], na_color="white", ), ) plotly.io.show(fig)