{ "cells": [ { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. _color-mapping:\n", "\n", "Color Mapping\n", "=============\n", "\n", "Color mapping is the process of mapping values in your data to colors in a plot. It allows you to increase the dimensionality of a graphic - for example, adding a third dimension to the two-dimensional x, y coordinates in a scatterplot. Good color mapping choices can reveal or emphasize patterns in your data while poor choices will obscure them, making color mapping an essential part of the Toyplot API.\n", "\n", "If you haven't already, see :ref:`colors` for information on basic color management in Toyplot for creating and manipulating color values, color palettes, and color maps.\n", "\n", "Mapping Data to Color\n", "---------------------\n", "\n", "There are a few decisions to make whenever you map colors in Toyplot:\n", "\n", "First, what is the cardinality of your data? Will you be specifying:\n", "\n", "* A constant color?\n", "* Per-series colors?\n", "* Per-datum colors?\n", "\n", "Second, for per-series or per-datum colors, will you specify:\n", "\n", "* A custom palette?\n", "* Explicit colors?\n", "* Scalar values that are mapped to colors?\n", "\n", "Third, if you choose to map scalars, will you provide:\n", "\n", "* Just scalar values?\n", "* Just a color map?\n", "* Both scalar values and a color map?\n", "\n", "We will examine all of these options in the examples that follow. To begin, let's create some random data series to use in our sample figures:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import numpy\n", "numpy.random.seed(1234)\n", "\n", "samples = numpy.linspace(0, 4 * numpy.pi, 100)\n", "frequency = lambda: numpy.random.normal()\n", "phase = lambda: numpy.random.normal()\n", "amplitude = lambda: numpy.random.uniform(0.1, 1)\n", "wave = lambda: numpy.sin(phase() + (frequency() * samples))\n", "signal = lambda: amplitude() * (2 + wave())\n", "\n", "series = numpy.column_stack([signal() for i in range(10)])\n", "single_series = series[:, 1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we'll display the data without specifying any color information. Here is a plot with a single series:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "