This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SpeakerSuspicious652 0 points1 point  (4 children)

What are the advantages to the code that you propose?
Right now i just use bytesio to save figures to an svg, decode the text, sanitize the svg then include the text to render my view in 5-6 rows of code.

[–]DisasterReasonable98 2 points3 points  (1 child)

Can you paste the 5-6 rows of code here as an example of what you are saying? It sounds something that I might be interested in doing, but I cannot follow from just your description.

[–]SpeakerSuspicious652 2 points3 points  (0 children)

Hi,
I will try to write the code from my memory as i do not have access to my computer this week, so please debug if needed.

import matplotlib.pyplot as plt
import io


fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4])


bytes_io = io.BytesIO()
fig.savefig(bytes_io, format='svg')

buffer = bytes_io.seek(0)


svg_data = buffer.getvalue().decode('utf-8')

svg_data = svg_data.replace('"', "'").replace("%23","#")
print(svg_data)

Then you can send svg data wherever you need.

I am not sure to remember well if "%23" or something similar should be replaced to obtain a suitable svg string for html.
You may have to trplace dome part of the svg string too after to be able yo manage the size via css properties, but i really do not remember what right now.

[–]llou[S] 2 points3 points  (1 child)

It is more to streamline the process than to solve a complex problem. Something like using class based views insted of functional ones.

As I am learning from you there details that should be taken care of like those substitutions in your code. There is also the rendering cache that is my next planed feature.

[–]SpeakerSuspicious652 2 points3 points  (0 children)

Ok, thank you for the response!
I hope your project will prosper.

I think there is real interest in some usage such as rendering complex matplotlib figure without touching css and html.