Plotting (ti_plotlib): TI-84 Evo Python

Axes, windows and data plots, the module TI built for graphing measurements. 21 functions in ti_plotlib, each with a working example.

Try any of these in CalcPlex PRGM, a browser code editor, which sends your program to a calculator over USB.

ti_plotlib.a

ti_plotlib.a

The slope from the last lin_reg(). Zero until a regression has run.

After lin_reg() runs, ti_plotlib.a holds the slope of the fitted line y = ax + b.

Round it before you show it, because the raw value has more decimal places than your measurements.

import ti_plotlib

xs = [1, 2, 3, 4, 5]
ys = [2.2, 4.1, 5.9, 8.2, 9.8]

ti_plotlib.cls()
ti_plotlib.auto_window(xs, ys)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.scatter(xs, ys, "x")
ti_plotlib.lin_reg(xs, ys, "center", 11)
ti_plotlib.show_plot()

ti_plotlib.cls()
print("y =", round(ti_plotlib.a, 3), "x +", round(ti_plotlib.b, 3))

After the plot is cleared, the equation is printed with the slope and intercept rounded to three places.

See also: ti_plotlib.b, ti_plotlib.lin_reg(, ti_plotlib.scatter(, ti_plotlib.cls(

ti_plotlib.auto_window(

ti_plotlib.auto_window(xlist, ylist)

Sets the window automatically so both lists of data fit on screen.

Picks the window for you. Hand it the two lists you are about to plot and it sets the range so they fit, with a little room on every side.

Call it where window() would go, after cls() and before anything is drawn. Read ti_plotlib.xmin and friends afterwards if you need the range it chose, for example to pick a grid spacing.

Watch out

If every value in a list is the same, there is no range to fit and auto_window raises an error (Invalid y list for autoscale when it is the y values). A flat series needs window() set by hand.

import ti_plotlib

# current in amps, voltage in volts
amps = [0.0, 0.0009, 0.0021, 0.0031, 0.0039, 0.005, 0.006]
volts = [0, 1, 2, 3.2, 4, 4.9, 5.8]

ti_plotlib.cls()
ti_plotlib.auto_window(amps, volts)

ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")

# six grid divisions, whatever range was chosen
ti_plotlib.grid((ti_plotlib.xmax - ti_plotlib.xmin) / 6, (ti_plotlib.ymax - ti_plotlib.ymin) / 6, "dot")
ti_plotlib.title("OHM'S LAW")

ti_plotlib.color(0, 0, 255)
ti_plotlib.scatter(amps, volts, "x")
ti_plotlib.show_plot()

Tiny numbers that would be annoying to window by hand. The grid spacing is computed from whatever range was chosen.

See also: ti_plotlib.window(, ti_plotlib.xmin, ti_plotlib.scatter(, ti_plotlib.grid(

ti_plotlib.axes(

ti_plotlib.axes("mode")

Draws the x and y axes on the plot.

Draws the two axis lines so a reader can tell where zero is. The four modes:

  • "on": the lines, plus the four window edge values written at their ends. The usual choice.
  • "axes": the lines only.
  • "window": the numbers only.
  • "off": nothing.

The numbers are the window bounds, not tick marks. If zero isn't inside the window, the axis sits on the nearest edge: with window(0, 45, 0, 20) the axes run along the left and the bottom.

The lines use the current pen().

Watch out

axes() uses whatever color is currently set, so call color(0, 0, 0) before it or the axes come out in the last color you used. A misspelled mode like "axis" silently draws nothing.

import ti_plotlib

ti_plotlib.cls()
ti_plotlib.window(-5, 5, -3.28, 3.28)

# set color BEFORE calling axes()
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")

# switch to red for the data point
ti_plotlib.color(200, 0, 0)
ti_plotlib.plot(2, 1.5, "o")
ti_plotlib.show_plot()

Axes drawn in black, then the color switched to red for the data point.

See also: ti_plotlib.grid(, ti_plotlib.window(, ti_plotlib.color(, ti_plotlib.labels(

ti_plotlib.b

ti_plotlib.b

The y-intercept from the last lin_reg(). Zero until a regression has run.

After lin_reg() runs, ti_plotlib.b holds the intercept of the fitted line y = ax + b: the y value where the line crosses x = 0.

import ti_plotlib

temp = [20, 30, 40, 50, 60]
volume = [50.4, 52.1, 53.8, 55.6, 57.2]

ti_plotlib.cls()
ti_plotlib.auto_window(temp, volume)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.scatter(temp, volume, "x")
ti_plotlib.lin_reg(temp, volume, "center", 11)
ti_plotlib.show_plot()

ti_plotlib.cls()
print("volume at 0 C =", round(ti_plotlib.b, 2))

The intercept predicts the volume at zero degrees.

See also: ti_plotlib.a, ti_plotlib.lin_reg(, ti_plotlib.scatter(, ti_plotlib.show_plot(

ti_plotlib.cls(

ti_plotlib.cls()

Clears the plot. Call it first.

Wipes the plot clean. It is the first call in almost every plot program, and it is how you start a second plot once the viewer has pressed CLEAR on the first.

A plot program always has the same shape: cls(), then the window, then a color and the axes, grid and title, then a color and the data, then show_plot().

Only the pixels go. The window, the color, the pen and the results in a and b all stay as they were. It clears the same drawing as ti_draw.clear(). Printed text is cleared with ti_system.disp_clr() instead.

import ti_plotlib

# first line of almost every plot program
ti_plotlib.cls()
ti_plotlib.window(-6, 6, -3.93, 3.93)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.grid(1, 1, "dot")
ti_plotlib.show_plot()

An empty set of axes. cls() first, then the window, then everything else.

See also: ti_plotlib.show_plot(, ti_plotlib.window(, ti_draw.clear(, ti_system.disp_clr(

ti_plotlib.color(

ti_plotlib.color(r, g, b)

Sets the color for everything drawn after it. Each value is 0 to 255.

Sets the color for every plotting call that follows, until the next color(). Red, green, blue, each 0 to 255. One tuple works too: color((r, g, b)).

Common colors:

  • (0, 0, 0): black
  • (255, 0, 0): red
  • (0, 0, 255): blue
  • (0, 150, 0): green

Set it right before each group of things you want in that color: black for the axes and title, then blue for the data, then red for a fitted line. The grid is the one thing with its own color. This is the same color setting as ti_draw.set_color(), so changing one changes the other.

import ti_plotlib

xs = [1, 2, 3, 4, 5]
ys = [2.1, 3.9, 6.2, 7.8, 10.1]

ti_plotlib.cls()
ti_plotlib.window(0, 6, 0, 11)

# black for the frame
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.grid(1, 2, "dot")
ti_plotlib.title("MEASURED VS EXPECTED")

# blue for the data
ti_plotlib.color(0, 0, 220)
ti_plotlib.scatter(xs, ys, "x")

# red for the comparison line
ti_plotlib.color(220, 0, 0)
ti_plotlib.pen("thin", "dash")
ti_plotlib.line(0, 0, 5.5, 11)

ti_plotlib.show_plot()

Three color groups: black for the frame, blue for the data, red for the comparison line.

See also: ti_plotlib.pen(, ti_plotlib.axes(, ti_plotlib.grid(, ti_draw.set_color(

ti_plotlib.grid(

ti_plotlib.grid(xscl, yscl, "style") or ti_plotlib.grid(xscl, yscl, "style", (r, g, b))

Draws grid lines at regular intervals so values can be read off the plot.

xscl is the spacing between vertical lines in your x units and yscl the spacing between horizontal lines in y units. Lines sit at multiples of the spacing counted from zero, not from the edge of the window.

Styles: "dot", "dash", "solid", "point"

The optional fourth argument is a color tuple, like (192, 192, 192). Without it the grid is light gray, whatever color() is set to.

Don't guess the spacing, compute it from the window: (ti_plotlib.xmax - ti_plotlib.xmin) / 8 gives eight divisions and keeps working when the window changes.

Watch out

A grid can have at most 50 lines in each direction. grid(1, 1, "dot") on a window 200 units wide asks for 200 and raises Invalid grid scale value. Computing the spacing from the window avoids it.

import ti_plotlib

ti_plotlib.cls()

# 24 hours across, temperature up
ti_plotlib.window(0, 24, 0, 15.7)

ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")

# a line every 2 hours and every 2 degrees, in pale blue
ti_plotlib.grid(2, 2, "dot", (170, 190, 220))

ti_plotlib.title("TEMPERATURE BY HOUR")
ti_plotlib.show_plot()

Grid spacing chosen in real units (2 hours, 2 degrees), with a custom color to keep it subtle.

See also: ti_plotlib.axes(, ti_plotlib.window(, ti_plotlib.xmin, ti_plotlib.color(

ti_plotlib.labels(

ti_plotlib.labels("xlabel", "ylabel", xrow, yrow)

Names the two axes. The last two numbers are text rows, not coordinates.

Writes a name for each axis. The x label is right-aligned on its row and the y label is left-aligned on its row.

The third and fourth arguments are text rows, numbered 1 to 12 down the screen, not coordinates. Row 12 is the bottom and row 1 is the top. They default to 12 and 2.

Writing a label clears its whole row first, including any part of the plot that crosses it.

Watch out

Rows 12 and 2 are exactly where axes("on") prints its numbers, so the default rows write the labels over them and both come out garbled. When you use both, put the labels on rows 11 and 3.

import ti_plotlib

ti_plotlib.cls()
ti_plotlib.window(0, 10, 0, 6.56)

ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.grid(1, 1, "dot")
ti_plotlib.title("SPRING EXTENSION")

# rows 11 and 3, just inside the axis numbers on rows 12 and 2
ti_plotlib.labels("mass kg", "cm", 11, 3)

ti_plotlib.color(0, 0, 200)
ti_plotlib.plot([1, 2, 3, 4], [1.2, 2.5, 3.7, 5.0], "o")
ti_plotlib.show_plot()

Axis names on rows 11 and 3, one row in from the numbers that axes("on") writes.

See also: ti_plotlib.title(, ti_plotlib.text_at(, ti_plotlib.axes(, ti_plotlib.window(

ti_plotlib.lin_reg(

ti_plotlib.lin_reg(xlist, ylist, "disp", row)

Fits a best-fit line through your data, draws it, and shows the equation.

Calculates the line of best fit, y = ax + b, draws it right across the window, and writes the equation on the plot.

"disp" is where the equation goes: "left", "center", or "right". row is a text row from 1 to 12. Both are optional and default to center on row 11.

Afterwards the numbers are in ti_plotlib.a (the slope) and ti_plotlib.b (the intercept).

The line uses the current pen() and color(), so set those first. Call it after scatter() so the line is drawn on top of the points.

Watch out

The equation clears its whole row before it is written, so anything else on that row disappears. If labels() is also using row 11, put the equation on row 10.

import ti_plotlib

# stretching a spring: mass in kg, extension in cm
mass = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
ext = [2.1, 3.9, 6.2, 7.8, 10.4, 12.1]

ti_plotlib.cls()
ti_plotlib.auto_window(mass, ext)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.title("HOOKE'S LAW")

# the points first, then the fitted line on top
ti_plotlib.color(0, 0, 220)
ti_plotlib.scatter(mass, ext, "x")

ti_plotlib.color(220, 0, 0)
ti_plotlib.pen("thin", "dash")
ti_plotlib.lin_reg(mass, ext, "center", 11)

ti_plotlib.show_plot()

# after CLEAR, print the results
ti_plotlib.cls()
print("slope a =", round(ti_plotlib.a, 3))
print("intercept b =", round(ti_plotlib.b, 3))

The fit is drawn as a dashed red line with its equation on row 11. After CLEAR, the slope and intercept are printed as numbers.

See also: ti_plotlib.scatter(, ti_plotlib.a, ti_plotlib.b, ti_plotlib.pen(

ti_plotlib.line(

ti_plotlib.line(x1, y1, x2, y2) or ti_plotlib.line(x1, y1, x2, y2, "arrow")

Draws a straight line between two points, optionally with an arrowhead.

Draws a straight segment from (x1, y1) to (x2, y2) in your data coordinates, not pixels, with the current pen() and color().

The last argument is optional. "arrow" adds an arrowhead at the (x2, y2) end, which is how to draw a force or a velocity. Leave it out for a plain line.

Watch out

These are graph coordinates, not pixels. line(0, 0, 200, 100) on the default -10 to 10 window shoots off the screen with no error.

import ti_plotlib

ti_plotlib.cls()
ti_plotlib.window(-6, 6, -3.93, 3.93)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.grid(1, 1, "dot")
ti_plotlib.title("TWO FORCES")

ti_plotlib.pen("medium", "solid")

# red arrow: 4 right, 2 up
ti_plotlib.color(200, 0, 0)
ti_plotlib.line(0, 0, 4, 2, "arrow")

# blue arrow: 2 left, 3 up
ti_plotlib.color(0, 0, 200)
ti_plotlib.line(0, 0, -2, 3, "arrow")

ti_plotlib.show_plot()

Two force vectors from the origin, each with an arrowhead.

See also: ti_plotlib.pen(, ti_plotlib.plot(, ti_plotlib.color(, ti_draw.draw_line(

ti_plotlib.pen(

ti_plotlib.pen("size", "style")

Sets the thickness and pattern for lines drawn after it.

Sets how lines look: line(), the connecting lines in plot(), the fitted line from lin_reg(), and the axes. Marks and the grid are not affected.

Sizes: "thin", "medium", "thick"

Styles: "solid", "dot", "dash", and "point", which draws no line at all

pen("thick") on its own sets the style back to solid, so pass both every time.

Watch out

ti_draw.set_pen spells its styles "dotted" and "dashed". Here those raise Invalid pen style, and "dotted" in the first slot raises Invalid pen size. In ti_plotlib it is "dot" and "dash".

import ti_plotlib

ti_plotlib.cls()
ti_plotlib.window(0, 10, 0, 6.56)

ti_plotlib.color(0, 0, 0)

# thin solid for the frame
ti_plotlib.pen("thin", "solid")
ti_plotlib.axes("on")

ti_plotlib.color(0, 0, 200)

# medium solid for measured data
ti_plotlib.pen("medium", "solid")
ti_plotlib.line(1, 1, 9, 5)

ti_plotlib.color(200, 0, 0)

# thin dashed for the prediction
ti_plotlib.pen("thin", "dash")
ti_plotlib.line(1, 1.5, 9, 6)

ti_plotlib.show_plot()

Three pen settings: thin frame, medium measured line, dashed prediction.

See also: ti_plotlib.color(, ti_plotlib.line(, ti_draw.set_pen(, ti_plotlib.lin_reg(

ti_plotlib.plot(

ti_plotlib.plot(xlist, ylist, "mark") or ti_plotlib.plot(x, y, "mark")

Draws points joined by lines, or a single point.

plot has two forms:

Two lists: draws a mark at every pair and joins them with lines, in order. Use it when the line between points means something, like a temperature through the day. The lists need at least two points.

Two numbers: draws one point. A one-item list is not the same thing.

Marks: "o" (filled dot, the default), "x", "+", "*" (a small plus), "." (a single pixel), and "" for lines with no marks. Lowercase only.

The connecting lines use the current pen(). The marks always draw the same.

Watch out

plot() with lists connects the dots. scatter() does not. If your points are separate measurements rather than a sequence, use scatter(), otherwise plot() draws a misleading zigzag between them.

import ti_plotlib

ti_plotlib.cls()
ti_plotlib.window(-3, 3, -1.97, 1.97)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.title("Y = X SQUARED / 4 - 1")

# sample the curve into two lists
xs = []
ys = []
x = -3
while x <= 3:
    xs.append(x)
    ys.append(x * x / 4 - 1)
    x = x + 0.25

# the list form: points joined by lines, no marks
ti_plotlib.color(0, 0, 220)
ti_plotlib.plot(xs, ys, "")

# the two-number form: one point, at the bottom of the curve
ti_plotlib.color(220, 0, 0)
ti_plotlib.plot(0, -1, "o")

ti_plotlib.show_plot()

A curve drawn as 25 joined points, with its lowest point marked in red.

See also: ti_plotlib.scatter(, ti_plotlib.line(, ti_plotlib.pen(, ti_plotlib.xmin

ti_plotlib.scatter(

ti_plotlib.scatter(xlist, ylist, "mark")

Draws one mark per data pair with no lines between them.

Draws one mark per pair and nothing between them, which is how measured data is usually shown.

Marks: "o" (filled dot, the default), "x", "+", "*" (a small plus), "." (a single pixel). Crosses read best when points are close together, since overlapping dots merge into a blob.

The two lists must be the same length. For a best-fit line through the points, call lin_reg() afterwards.

Watch out

scatter(xs, ys, "O") raises Invalid mark. The mark is the one argument in this module where capitals matter.

import ti_plotlib

# height in cm and shoe size, one pair per classmate
height = [152, 158, 161, 165, 168, 170, 174, 179]
shoe = [4, 5, 5.5, 6, 7, 7, 8, 9.5]

ti_plotlib.cls()
ti_plotlib.window(145, 185, 3, 11)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.grid(5, 1, "dot")
ti_plotlib.title("HEIGHT VS SHOE SIZE")
ti_plotlib.labels("cm", "size", 11, 3)

ti_plotlib.color(0, 0, 220)
ti_plotlib.scatter(height, shoe, "x")
ti_plotlib.show_plot()

Eight measured pairs as crosses, with no lines between them.

See also: ti_plotlib.plot(, ti_plotlib.lin_reg(, ti_plotlib.auto_window(, ti_plotlib.pen(

ti_plotlib.show_plot(

ti_plotlib.show_plot()

Puts the plot on screen and holds it until CLEAR is pressed.

Switches the screen from the Python shell to the plot and holds it there until CLEAR is pressed. Until you call it, nothing you plotted is visible.

It goes last, after all the setup and data calls. When the user presses CLEAR the program carries on, with the plot still on screen. To show a second plot, call cls() and build the next one.

Only CLEAR works. ENTER and the other keys are ignored.

Watch out

Don't call it inside a loop. Every call waits for a CLEAR, so a loop that calls it on each pass stops on every single pass.

import ti_plotlib

days = [1, 2, 3, 4, 5, 6, 7]
plants = [0.5, 1.1, 1.9, 2.6, 3.4, 4.0, 4.9]

ti_plotlib.cls()
ti_plotlib.window(0, 8, 0, 5.25)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.grid(1, 1, "dot")
ti_plotlib.title("SEEDLING HEIGHT")
ti_plotlib.labels("day", "cm", 11, 3)

ti_plotlib.color(0, 150, 0)
ti_plotlib.pen("medium", "solid")
ti_plotlib.plot(days, plants, "o")

# LAST: now the plot actually appears
ti_plotlib.show_plot()

Seven days of measurements as a connected line. The plot only appears when show_plot() runs.

See also: ti_plotlib.cls(, ti_plotlib.window(, ti_draw.show_draw(, ti_plotlib.plot(

ti_plotlib.text_at(

ti_plotlib.text_at(row, "text", "align")

Writes a line of text on the plot at a given row.

Writes text onto the plot, for a reading, a note, or an instruction. row is a whole number from 1 (top) to 12 (bottom) and align is "left", "center", or "right".

The whole row is cleared first, including any part of the plot that crosses it, so writing to the same row again replaces what was there. Text that doesn't fit is cut off at the edge.

Watch out

row is a text row from 1 to 12, not a pixel or a y coordinate. Rows 0 and 13 raise an error.

import ti_plotlib

ti_plotlib.cls()
ti_plotlib.color(0, 0, 200)
ti_plotlib.text_at(2, "SPRING EXPERIMENT", "center")
ti_plotlib.text_at(3, "six masses measured", "center")

ti_plotlib.color(0, 0, 0)
slope = 20.4
ti_plotlib.text_at(6, "k = %.1f N/m" % slope, "center")

ti_plotlib.color(200, 0, 0)
ti_plotlib.text_at(12, "press clear to quit", "right")

ti_plotlib.show_plot()

Four lines of text placed by row and alignment. The % formatting builds a string from a number.

See also: ti_plotlib.title(, ti_plotlib.labels(, ti_system.disp_at(, ti_plotlib.cls(

ti_plotlib.title(

ti_plotlib.title("title")

Writes a centered heading on the top row of the plot.

Writes a heading centered on the top row, in the current color().

About 32 characters fit. Anything longer is cut off at the edge with no warning, so keep it short.

import ti_plotlib

ti_plotlib.cls()
ti_plotlib.window(0, 12, 0, 7.87)

ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.title("RAINFALL BY MONTH")

ti_plotlib.color(0, 90, 200)
ti_plotlib.plot([1, 2, 3, 4, 5, 6], [4.1, 3.2, 5.6, 2.8, 6.4, 5.1], "o")
ti_plotlib.show_plot()

A short heading at the top, with data drawn underneath in blue.

See also: ti_plotlib.labels(, ti_plotlib.text_at(, ti_plotlib.color(, ti_plotlib.show_plot(

ti_plotlib.window(

ti_plotlib.window(xmin, xmax, ymin, ymax)

Sets the range of x and y values the plot covers.

Sets the smallest and largest x and y the screen shows. Everything you plot afterwards is placed against that range: with window(0, 45, 0, 20), the point (30, 15) lands two-thirds of the way across and three-quarters of the way up.

The defaults are -10, 10, -6.56, 6.56, chosen so that one unit across is the same size as one unit up. To keep that with your own x range, make the y half-range the x half-range divided by 1.526.

Points outside the window are not an error, they just don't show up. If a plot comes out empty, check that the data fits the window. xmin must be less than xmax and ymin less than ymax.

import ti_plotlib

# minutes spent studying, and the quiz score out of 20
mins = [5, 10, 15, 20, 25, 30, 35, 40]
score = [7, 8, 11, 12, 14, 15, 17, 18]

ti_plotlib.cls()

# x from 0 to 45, y from 0 to 20
ti_plotlib.window(0, 45, 0, 20)

ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.title("STUDY TIME VS SCORE")

ti_plotlib.color(0, 0, 255)
ti_plotlib.scatter(mins, score, "x")
ti_plotlib.show_plot()

Eight points placed against a window of 0 to 45 across and 0 to 20 up.

See also: ti_plotlib.auto_window(, ti_plotlib.xmin, ti_plotlib.cls(, ti_plotlib.show_plot(

ti_plotlib.xmax

ti_plotlib.xmax

The right edge of the current window. Default 10.

Reads back the right edge of the plotting window, set by window() or auto_window().

xmax - xmin is the full width of the window in your units, which is what you need for a grid spacing or a sampling step.

import ti_plotlib

ti_plotlib.cls()
ti_plotlib.window(0, 20, 0, 13.1)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.color(0, 0, 200)

# sample a curve across exactly the visible range
steps = 40
dx = (ti_plotlib.xmax - ti_plotlib.xmin) / steps
x = ti_plotlib.xmin
for i in range(steps + 1):
    ti_plotlib.plot(x, 0.03 * x * x, "o")
    x = x + dx

ti_plotlib.show_plot()

The sampling step adapts to the window, so the curve fills the plot whatever range you choose.

See also: ti_plotlib.xmin, ti_plotlib.ymax, ti_plotlib.window(, ti_plotlib.grid(

ti_plotlib.xmin

ti_plotlib.xmin

The left edge of the current window. Default -10.

Reads back the left edge of the plotting window, set by window() or chosen by auto_window().

All four are available: xmin, xmax, ymin, ymax. Defaults are -10, 10, -6.56, 6.56.

Use them instead of hardcoding numbers and everything adapts when the window changes. A grid spacing of (xmax - xmin) / 8 stays sensible whatever range you pick.

Watch out

Read these, don't assign to them. ti_plotlib.xmax = 20 gives no error, but the plot stays scaled to the old window and points land in the wrong place. Change the window with window().

import ti_plotlib

ti_plotlib.cls()
ti_plotlib.window(-4, 4, -2.62, 2.62)

ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.grid((ti_plotlib.xmax - ti_plotlib.xmin) / 8, (ti_plotlib.ymax - ti_plotlib.ymin) / 6, "dot")

width = ti_plotlib.xmax - ti_plotlib.xmin
ti_plotlib.text_at(1, "window is %.1f units wide" % width, "center")
ti_plotlib.show_plot()

The grid spacing and the caption are both computed from the window, so changing the window() call updates everything.

See also: ti_plotlib.xmax, ti_plotlib.ymin, ti_plotlib.window(, ti_plotlib.auto_window(

ti_plotlib.ymax

ti_plotlib.ymax

The top edge of the current window. Default 6.56.

Reads back the top edge of the plotting window.

ymax - ymin is the full height in your units, for a grid spacing or for placing something a fraction of the way up the plot.

import ti_plotlib

readings = [3.1, 4.6, 4.2, 5.9, 6.4, 6.1, 7.2]
days = [1, 2, 3, 4, 5, 6, 7]

ti_plotlib.cls()
ti_plotlib.auto_window(days, readings)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.grid((ti_plotlib.xmax - ti_plotlib.xmin) / 7, (ti_plotlib.ymax - ti_plotlib.ymin) / 5, "dot")

ti_plotlib.color(0, 0, 200)
ti_plotlib.scatter(days, readings, "o")

# a dashed red line three-quarters of the way up
level = ti_plotlib.ymin + 0.75 * (ti_plotlib.ymax - ti_plotlib.ymin)
ti_plotlib.color(200, 0, 0)
ti_plotlib.pen("thin", "dash")
ti_plotlib.line(ti_plotlib.xmin, level, ti_plotlib.xmax, level)
ti_plotlib.show_plot()

The grid and the marker line are placed as fractions of whatever range auto_window picked.

See also: ti_plotlib.ymin, ti_plotlib.xmax, ti_plotlib.auto_window(, ti_plotlib.line(

ti_plotlib.ymin

ti_plotlib.ymin

The bottom edge of the current window. Default -6.56.

Reads back the bottom edge of the plotting window.

The default of -6.56 makes one unit across the same size as one unit up, so circles look round and squares look square. To keep that with your own x range, divide the x half-range by 1.526 to get the y half-range.

import ti_plotlib

# build a square-looking window around any x range
x_half = 8
y_half = round(x_half / 1.526, 2)

ti_plotlib.cls()
ti_plotlib.window(-x_half, x_half, -y_half, y_half)
ti_plotlib.color(0, 0, 0)
ti_plotlib.axes("on")
ti_plotlib.grid(2, 2, "dot")
ti_plotlib.text_at(1, "ymin is %.2f" % ti_plotlib.ymin, "center")
ti_plotlib.show_plot()

A window built to the screen's proportions, so the grid squares come out square.

See also: ti_plotlib.ymax, ti_plotlib.xmin, ti_plotlib.window(, ti_draw.get_screen_dim(