Skip to content

visualize

Visualize¤

BenchmarkCharts (Charts) ¤

Create charts of benchmarks.

from colorteller import teller
from colorteller.utils import benchmark
from colorteller.visualize import BenchmarkCharts, ApplicationCharts

hex_strings = ["#8de4d3", "#344b46", "#74ee65", "#238910", "#a6c363", "#509d99"]

ct = teller.ColorTeller(hex_strings=hex_strings)
c = teller.Colors(colorteller=ct)
m = c.metrics(
    methods=[benchmark.PerceptualDistanceBenchmark, benchmark.LightnessBenchmark]
)

charts = BenchmarkCharts(metrics=m, save_folder=".")
charts.distance_matrix(show=False)
charts.noticable_matrix(show=False)

Parameters:

Name Type Description Default
metrics list

a list of benchmark metrics. It is created by teller.Colors object. Use teller.Colors.metrics(methods=[colorteller.utils.PerceptualDistanceBenchmark, colorteller.utils.LightnessBenchmark])

required
save_folder Union[str, Path]

the folder to save the charts to.

required

Charts ¤

A base class for charts. This class is not meant to be used directly.

Parameters:

Name Type Description Default
save_folder

which folder to save the charts to.

required

_save_fig(self, save_to, name) private ¤

Save fig to file. Only call this method after establishing a matplotlib axis object (ax)

Parameters:

Name Type Description Default
save_to

the path to save the figure as. If this is set to True, the figure will be saved to self.save_folder / name. If this is set to a specific path, the figure will be saved to that path.

required
Source code in colorteller/visualize.py
def _save_fig(self, save_to, name):
    """Save fig to file. Only call this method after establishing a matplotlib axis object (ax)

    :param save_to: the path to save the figure as. If this is set to `True`, the figure will be saved to `self.save_folder / name`. If this is set to a specific path, the figure will be saved to that path.
    """

    if save_to is None:
        pass
    elif save_to is True:
        if self.save_folder is None:
            logger.error("No save folder specified for Charts")
        else:
            plt.savefig(self.save_folder / name)
    else:
        plt.savefig(save_to)

    plt.clf()