Combine Plots of SageMath and Matplotlib

42 views Asked by At

How can I combine plots from Sage and Matplotlib into a single plot without one overlaying the other?

Here's an example script where I attempt to combine Sage and Matplotlib plots:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]
ax.plot(x, y)

c = circle((1,1),1)
c_matplotlib = c.matplotlib(figure=fig)  # this Returns matplotlib.figure.Figure object

plt.show()

However, when I run this script, Sage just puts another image on top of the canvas of Matplotlib. Is there a way to update the canvas of Matplotlib to combine the two plots into one?

Image

enter image description here

Reference

1

There are 1 answers

0
Rowing0914 On

Working Solution by JohanC

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]
ax.plot(x, y)
c = circle((1,1),1)
c_matplotlib = c.matplotlib(figure=fig, sub=ax)
plt.show()

enter image description here