Plots (Sage)
Plots that add up, points and labels, and interacts with sliders.
plotsinteractiveDownload (ZIP)Source on GitHub
Preview
# Hover over a plot to read coordinates
plot(sin(x^2), (x, 0, 2*pi), color='red', legend_label='sin(x^2)', title='sin(x^2)')# Graphics add up
g = plot(x^3 - 3*x, (x, -2.2, 2.2), thickness=2)
g += point([(-1, 2), (1, -2)], size=60, color='red')
g += text('local max', (-1, 2.5)) + text('local min', (1, -2.5))
g# Drag the slider
@interact
def rose(n=slider(1, 12, 1, 5), color=selector(['blue', 'green', 'purple']), filled=False):
g = polar_plot(cos(n*x), (x, 0, 2*pi), color=color, thickness=2)
if filled:
g += disk((0, 0), 1, alpha=0.1)
show(g, figsize=4.5)@interact
def damped(a=(0.1, 3.0), w=(1, 12)):
show(plot(exp(-a*x)*sin(w*x), (x, 0, 6), fill='axis', gridlines=True, ymin=-1, ymax=1, figsize=(7, 3)))# The prime counting function against the PNT prediction (press ▶)
@interact
def f(N=(10, 1000, 5)):
show(list_plot([prime_pi(k) for k in range(3, N)], plotjoined=True, legend_label='prime_pi') +
plot(x/(log(x) - 1), (x, 3, N), color='red', legend_label='x/(log(x)-1)'))# animate: frames on common axes; the result is an animated SVG
a = animate([plot(sin(x - k)*exp(-x/6), (x, 0, 4*pi), fill='axis', thickness=2) for k in srange(0, 2*pi, 0.2)], figsize=(7, 3))
a.show(delay=5)3D
Drag to turn a scene (flick it to spin), right-drag to pan, click it and scroll to zoom toward the cursor, double-click a surface to orbit that point. Press F (or Fly) to fly through it like a game: the mouse looks around, W A S D move, Space and Q go up and down, Shift is faster.
# The Platonic solids; translate, rotate and scale move any 3D graphics
icosahedron(color='orange', opacity=0.5).translate((0, 0, 1)) + tetrahedron()sum(s(center=(3*k, 0, 0), color=c) for k, (s, c) in enumerate([(tetrahedron, 'red'), (cube, 'gold'), (octahedron, 'green'), (dodecahedron, 'blue'), (icosahedron, 'purple')]))x, y, z = var('x y z')
implicit_plot3d(x^4 - 5*x^2 + y^4 - 5*y^2 + z^4 - 5*z^2 + 11.8, (x, -2.5, 2.5), (y, -2.5, 2.5), (z, -2.5, 2.5), color='gold')Files
main.ipynb(584664 bytes)