Sympy plotting module save figure as svg string

15 views
Skip to first unread message

Anton Makarov

unread,
Nov 21, 2022, 5:57:08 AM11/21/22
to sympy
Hi, i need to save figure from svg plotting module as svg string in order to
insert it latter in my web application. At the moment i can only save plot as svg file:

from sympy import symbols
from sympy.plotting import plot

x = symbols('x')
p1 = plot(x, x**2, x**3, (x, 0, 6), show = False)
p1.save("img123.svg")

How can i save plot to get the svg string (P.S. i don't want to read the file "img123.svg" to get the svg string, i need to get it without creating temporary file)...

Oscar Benjamin

unread,
Nov 21, 2022, 8:51:22 AM11/21/22
to sy...@googlegroups.com
SymPy's save function is just using matplotlib so the question is not
really about SymPy but about matplotlib:
https://stackoverflow.com/questions/5453375/matplotlib-svg-as-string-and-not-a-file

Oscar
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/c65df323-b088-4cd3-9234-0381822eb686n%40googlegroups.com.

Антон Макаров

unread,
Nov 21, 2022, 9:01:00 AM11/21/22
to sympy
Thank you for answer. As far as I can understand the p1 variable in my sample code is the object of mathplotlib library, right?



Отправлено из мобильной Почты Mail.ru


понедельник, 21 ноября 2022 г., 16:51 +0300 от oscar.j....@gmail.com <oscar.j....@gmail.com>:

Oscar Benjamin

unread,
Nov 21, 2022, 11:52:48 AM11/21/22
to sy...@googlegroups.com
I don't know how you get the handle to the matplotlib figure but there
should be some way to do it.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/1669039248.989992473%40f727.i.mail.ru.

Антон Макаров

unread,
Nov 21, 2022, 11:54:12 AM11/21/22
to sympy
Thanks, i’ve already solve the problem…



Отправлено из мобильной Почты Mail.ru


понедельник, 21 ноября 2022 г., 19:52 +0300 от oscar.j....@gmail.com <oscar.j....@gmail.com>:
Reply all
Reply to author
Forward
0 new messages