Ask Your Question

Revision history [back]

First, you should define the polynomial ring so that you can define the polynomial:

sage: R.<x,y> = ZZ[]
sage: R
Multivariate Polynomial Ring in x, y over Integer Ring

Then, you can define your polynomial:

sage: P = 3+4*x+8*x^2+7*y+2*x*y
sage: P
8*x^2 + 2*x*y + 4*x + 7*y + 3

A handy way to get the coefficients and exponents of the polynomial is by using the dict method:

sage: d = P.dict()
sage: d
{(2, 0): 8, (1, 1): 2, (1, 0): 4, (0, 1): 7, (0, 0): 3}
sage: list(d.items())
[((2, 0), 8), ((1, 1), 2), ((1, 0), 4), ((0, 1), 7), ((0, 0), 3)]

Now, you can start from an empty graphics and add the text elements one by one:

sage: G = Graphics()
sage: for (x,y),t in d.items():
....:     G += text(str(t),(x,y))

Then, you can see your plot:

sage: G

You can also tune your plot, e.g. by removing the axes:

sage: G.show(axes=False)
Launched png viewer for Graphics object consisting of 5 graphics primitives

First, you should define the polynomial ring so that you can define the polynomial:

sage: R.<x,y> = ZZ[]
sage: R
Multivariate Polynomial Ring in x, y over Integer Ring

Then, you can define your polynomial:

sage: P = 3+4*x+8*x^2+7*y+2*x*y
sage: P
8*x^2 + 2*x*y + 4*x + 7*y + 3

A handy way to get the coefficients and exponents of the polynomial is by using the dict method:

sage: d = P.dict()
sage: d
{(2, 0): 8, (1, 1): 2, (1, 0): 4, (0, 1): 7, (0, 0): 3}
sage: list(d.items())
[((2, 0), 8), ((1, 1), 2), ((1, 0), 4), ((0, 1), 7), ((0, 0), 3)]

Now, you can start from an empty graphics and add the text elements one by one:

sage: G = Graphics()
sage: for (x,y),t in d.items():
....:     G += text(str(t),(x,y))
text(t, (x, y))

Then, you can see your plot:

sage: G

You can also tune your plot, e.g. by removing the axes:

sage: G.show(axes=False)
Launched png viewer for Graphics object consisting of 5 graphics primitives