We need to refine the way users specify colors, to simplify the public API and eliminate inconsistencies. The challenge is to handle all of the ways in which a user might want to specify per-series / per-datum colors, while avoiding potential ambiguities.
Use-cases
toyplot.plot(x, y, color="red")
toyplot.plot(x, y, color=["red", "cinnamon", "cardinal"])
toyplot.plot(x, y, color=toyplot.color.brewer("reds"))
toyplot.plot(x, y, color=toyplot.color.LinearMap(toyplot.color.Palette(["red", "green", "blue"])))
toyplot.plot(x, y, color=temperature)
colors = toyplot.color.broadcast(temperature)
colors[numpy.argsort(temperature)[0]] = "blue"
colors[numpy.argsort(temperature)[-1]] = "red"
toyplot.plot(x, y, color=colors)
toyplot.plot(x, y, color=mycolors)
API
toyplot.color.broadcast(...) always returns a numpy color array (array with dtype == toyplot.color.dtype), with the given shape.
Values
In [1]:
import numpy
x = numpy.linspace(0, 1)
y = numpy.column_stack((x ** 2, x ** 3))
numpy.random.seed(1234)
temperature = numpy.random.uniform(size=y.shape)
In [2]:
import toyplot
In [3]:
toyplot.scatterplot(x, y, width=300);
In [4]:
toyplot.scatterplot(x, y, color="red", width=300);
In [5]:
toyplot.scatterplot(x, y, color=["red", "blue"], width=300);
In [6]:
toyplot.scatterplot(x, y, fill=temperature, width=300);
In [7]:
toyplot.scatterplot(x, y, fill=(temperature, toyplot.color.brewer("BlueRed")), width=300);
In [8]:
toyplot.scatterplot(x, y, fill=(temperature, toyplot.color.LinearMap()), width=300);
In [9]:
colors = toyplot.color.broadcast((temperature, toyplot.color.brewer("Greys")), y.shape)
colors[20:30, 1] = toyplot.color.css("yellow")
colors.flat[numpy.argmin(temperature)] = toyplot.color.css("blue")
colors.flat[numpy.argmax(temperature)] = toyplot.color.css("red")
toyplot.scatterplot(x, y, fill=colors, width=300);
In [10]:
x = numpy.linspace(0, 1)
y = x ** 2
In [11]:
toyplot.bars(y, fill=(x, toyplot.color.brewer("Reds")), width=300);
In [12]:
toyplot.bars(y, fill=toyplot.color.brewer("Reds"), width=300);
In [13]:
toyplot.fill(x, numpy.column_stack((y, y/2, y/3, y/4, y/5)), baseline="symmetric", fill=(numpy.arange(5), toyplot.color.brewer("Reds")), width=300);
In [14]:
toyplot.fill(x, numpy.column_stack((y, y/2, y/3, y/4, y/5)), baseline="symmetric", fill=toyplot.color.brewer("Reds"), width=300);
In [15]:
toyplot.scatterplot(x, numpy.column_stack((y, y/2, y/3, y/4, y/5)), color=(numpy.arange(5), toyplot.color.brewer("Reds")), width=300);
In [16]:
toyplot.scatterplot(x, numpy.column_stack((y, y/2, y/3, y/4, y/5)), color=toyplot.color.brewer("Reds"), width=300);
In [17]:
canvas = toyplot.Canvas(width=300)
axes = canvas.axes()
axes.text(x, y, y, fill=(x, toyplot.color.brewer("Reds")));
In [18]:
canvas = toyplot.Canvas(width=300)
axes = canvas.axes()
axes.text(x, y, y, fill=toyplot.color.brewer("Reds"));
In [19]:
canvas = toyplot.Canvas(width=300)
axes = canvas.axes()
axes.hlines(x, stroke=(x, toyplot.color.brewer("Reds")));
In [20]:
canvas = toyplot.Canvas(width=300)
axes = canvas.axes()
axes.hlines(x, stroke=toyplot.color.brewer("Reds"));
In [21]:
canvas = toyplot.Canvas(width=300)
axes = canvas.axes()
axes.vlines(x, stroke=(x, toyplot.color.brewer("Reds")));
In [22]:
canvas = toyplot.Canvas(width=300)
axes = canvas.axes()
axes.vlines(x, stroke=toyplot.color.brewer("Reds"));
In [ ]: