Skip to main content

We'll keep it simple. Desmos is one of the best online calculators. Python is one of the best programming languages. So why no Python API? Who knows. What we do know is that PyDesmos is the next best thing.

We've made it as easy as possible to interact with Desmos from python:

from PyDesmos import Graph
with Graph('my graph') as G:
    f, x = G.f, G.x
    f[x] = x ** 2

With just these four lines: an HTML file called "my graph.html" containing a Desmos graph with the expression "f(x)=x^2" already written, is compiled and then automatically opened in your favorite browser!

Magic? Yes. But that's not all. We've pushed Python's syntax to its limits to make your experience as simple as possible. Our flexible code incidentally allows many alternatives to f[x] = x ** 2, depending on your style / needs:

G.append('f(x)=x^2')
G.define('f(x)', x ** 2)  # 'f(x)' is also equivalent to f(x) (yes, without quotes)
G.eq(f(x), x ** 2)
G(f(x), '=', x ** 2)
G(f(x), x ** 2)
G[f(x)] = x ** 2

Many more things are made easy. For example, plotting tables:

G.new_table({x: [0, 1, 2], y: [2, 3, 5]})  # where x, y = G.x, G.y, OR
G(x=[0, 1, 2], y=[2, 3, 5])

Plotting python functions:

f = lambda x: int(str(x)[::-1])
G.plot_function(f, 0, 100)  # OR
G(f, min=0, max=100)

Since Desmos uses latex to generate expressions, all latex-friendly sympy expressions get automatically converted.

import sympy as sp
with Graph('my graph') as G:
    x, y = G.x, G.y
    G.le(sp.factorial(x + y), sp.sin(x - y))  # appends the expression "(x+y)! <= sin(x-y)"

Sliders and greek letter support:

G(alpha=0, min=0, max=2 * G.pi, step=G.pi / 2)  # appends the constant "α=0" with respective bounds

Yet another way to append expressions:

G | sympy.sin(2 * G.x)  # appends the expression "sin(2x)"

Points:

G(p=(0,0))  # appends the point "p=(0,0)"

Prime-notation:

G | (f^1)(x)  # appends the expression "f'(x)", where f, x = G.f, x.f

Subscript notation:

G(c[0], 42)  # appends the expression "c_{0}=42", where c = G.c

...

Alright, I'm sure you get it. PyDesmos is awesome. But one last thing. All of these methods have additional (optional) kwargs for absolute customization, such as color, line thickness, etc. You may read about them here, under "expression_state Name and Values". For example,

G(y=G.x ** 2, color='#FF0000')  # appends the expression "y=x^2" with color #FF0000.

Happy PyDesmos-ing!


New: To plot a sequence from the OEIS:

G.plot_oeis('A000001')  # optional max_terms parameter

Or to just get a dictionary:

A000001 = oeis('A000001')  # returns {0: 0, 1: 1, ...}

Query support:

G.plot_oeis('the prime numbers')  # OR
G.plot_oeis([2, 3, 5, 7])

Related method with the OEIS

oeis_query('the prime numbers')  # returns a list of the first few most relevant sequence ids

Change Log

0.0.1 (12/04/2023)

  • First Release

0.1.0 (12/04/2023)

  • Entered Alpha
  • Major code revisions
  • improved README.md

0.1.1 (13/04/2023)

  • Minor tweaks (mostly to README.md)
  • Fixed optional kwargs with tables

0.1.2 (13/04/2023)

  • Added simple OEIS integration
  • Added support for all greek letters

0.1.3 (13/04/2023)

  • Increased OEIS support. (allows for querying the most relevant sequences based off a list of terms or keywords)

Release files for PyDesmos 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyDesmos 0.1.3
File Size Uploaded
PyDesmos-0.1.3.tar.gz 14.1 kB Details

Release files / PyDesmos-0.1.3.tar.gz

Download URL PyDesmos-0.1.3.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f22d353430fe87118a84da105437cdeb5e292ba875b062d9978c3a639f3e0d6c
BLAKE2b-256 checksum
How to use checksums
e7cecc986d5e84483fff6d00e60cc002acb7ac7f0c20ddd10d509e23fdba9e50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page