_images/toyplot.png

Logarithmic ScalesΒΆ

In Toyplot, individual axes supplied by toyplot.coordinates.Cartesian and toyplot.coordinates.Numberline provide mappings from data values to canvas coordinates. An important property of each axis is its scale, used to specify linear or logarithmic mappings from domain to range:

[1]:
import numpy
x = numpy.linspace(-1000, 1000, 51)
[2]:
import toyplot
canvas = toyplot.Canvas(width=600, height=200)

numberline = canvas.numberline(grid=(2, 1, 0, 0), scale="linear")
numberline.scatterplot(x)

numberline = canvas.numberline(grid=(2, 1, 1, 0), scale="log")
numberline.scatterplot(x);
-1000-50005001000-10 3-10 2-10 1-10 0010 010 110 210 3

Or in two dimensions:

[3]:
canvas = toyplot.Canvas(width=700)

axes = canvas.cartesian(grid=(2, 2, 0, 0), xscale="linear", yscale="linear")
axes.plot(x, x, marker="o")

axes = canvas.cartesian(grid=(2, 2, 0, 1), xscale="log", yscale="linear")
axes.plot(x, x, marker="o")

axes = canvas.cartesian(grid=(2, 2, 1, 0), xscale="linear", yscale="log")
axes.plot(x, x, marker="o")

axes = canvas.cartesian(grid=(2, 2, 1, 1), xscale="log", yscale="log")
axes.plot(x, x, marker="o");
-1000-50005001000-1000-50005001000-10 3-10 2-10 1-10 0010 010 110 210 3-1000-50005001000-1000-50005001000-10 3-10 2-10 1-10 0010 010 110 210 3-10 3-10 2-10 1-10 0010 010 110 210 3-10 3-10 2-10 1-10 0010 010 110 210 3

Note that Toyplot handles negative values correctly, and provides sensible results for values near zero by rendering them using a small linear region around the origin.

The scale can be specified in two ways:

  • As a string - β€œlinear”, β€œlog” (base 10), β€œlog10” (base 10), or β€œlog2” (base 2).
  • As a tuple - (β€œlog”, 2), (β€œlog”, 10).

For example, the following are all equivalent

[4]:
canvas = toyplot.Canvas(width=600, height=300)

numberline = canvas.numberline(grid=(3,1,0), scale="log")
numberline.scatterplot(x)

numberline = canvas.numberline(grid=(3,1,1), scale="log10")
numberline.scatterplot(x)

numberline = canvas.numberline(grid=(3,1,2), scale=("log", 10))
numberline.scatterplot(x);
-10 3-10 2-10 1-10 0010 010 110 210 3-10 3-10 2-10 1-10 0010 010 110 210 3-10 3-10 2-10 1-10 0010 010 110 210 3

Of course, you are free to specify any base you like, using the tuple notation:

[5]:
canvas = toyplot.Canvas(width=600, height=100)
numberline = canvas.numberline(scale=("log", 4))
numberline.scatterplot(x);
-4 5-4 4-4 3-4 2-4 1-4 004 04 14 24 34 44 5