figurefirst
figurefirst copied to clipboard
Template with several other elements
Hello,
is it possible to use a template that has other elements like text, arrows? Something like this:
When I try that template:
import figurefirst as fifi
import matplotlib.pyplot as plt
import numpy as np
layout = fifi.FigureLayout('template.svg')
layout.make_mplfigures()
x = np.linspace(0, 2*np.pi, 200)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = np.sinc(x)
axes = layout.axes
axes['mainaxis'].plot(x, y1)
axes['secondaxis'].plot(x, y2)
axes['thirddaxis'].plot(x, y3)
layout.insert_figures()
layout.write_svg('out.svg')
I get the following error:
Traceback (most recent call last):
File "test.py", line 5, in <module>
layout = fifi.FigureLayout('template.svg')
File "/home/significantcell2/.local/lib/python3.8/site-packages/figurefirst/svg_to_axes.py", line 732, in __init__
figuretree,grouptree,leafs,svgitemtree = self.make_group_tree()
File "/home/significantcell2/.local/lib/python3.8/site-packages/figurefirst/svg_to_axes.py", line 867, in make_group_tree
traverse_svgitems(self.layout,svgitemtree)
File "/home/significantcell2/.local/lib/python3.8/site-packages/figurefirst/svg_to_axes.py", line 860, in traverse_svgitems
traverse_svgitems(child,tree_loc)
File "/home/significantcell2/.local/lib/python3.8/site-packages/figurefirst/svg_to_axes.py", line 860, in traverse_svgitems
traverse_svgitems(child,tree_loc)
File "/home/significantcell2/.local/lib/python3.8/site-packages/figurefirst/svg_to_axes.py", line 856, in traverse_svgitems
item = FFSVGItem(child)
File "/home/significantcell2/.local/lib/python3.8/site-packages/figurefirst/svg_to_axes.py", line 256, in __init__
x = float(self.node.getAttribute('x'))
ValueError: could not convert string to float: ''
I 've attached template.svg
here:
template.zip
Something is wrong with svgitem
tag in your svg. As I understand, you have a group of objects (texts and an arrow) tagged as a svgitem
, and that group does not have an x attribute, which causes the error. I tried removing svgitem
tag from your svg file and then the code runs.
I guess if you want to tag a group, you need to use the svggroup
tag, or tag individual objects as svgitems. There is an example about svgitems: https://github.com/FlyRanch/figurefirst/tree/master/examples/svgitems
In case you just want these elements to be present in the output, you can put them into a different layer and then you don't need any tags (see template_layer2.svg). template_layer2.zip
Hope this helps.
@kukasyachka : Thank you very much.
@kukasyachka : Is it ok to ask questions here? Is it possible to change text using figureFirst module, I mean I have to create a text placeholder in the template then add the text from the Python code.
Thanks
Yes you can change text, but the documentation on that functionality is somewhat sparse. There are some basic examples in the directory Anna pointed out, specifically, this notebook and associated template file: https://github.com/FlyRanch/figurefirst/blob/master/examples/svgitems/svgitem_editing_example.ipynb
On Wed, Jul 15, 2020 at 10:27 AM SignificantCell2 [email protected] wrote:
@kukasyachka https://github.com/kukasyachka : Is it ok to ask questions here? Is it possible to change text using figureFirst module, I mean I have to create a text placeholder in the template then add the text from the Python code.
Thanks
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FlyRanch/figurefirst/issues/61#issuecomment-658899230, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB4EPCGTJGF66KJ4IEIUD3R3XRHZANCNFSM4O2TWGTA .
-- Floris van Breugel | http://www.florisvanbreugel.com Assistant Professor of Mechanical Engineering & Graduate Program for Neuroscience Palmer 226, University of Nevada, Reno
Wildlife and Landscape Photography Galleries: http://www.ArtInNaturePhotography.com/ http://www.artinnaturephotography.com/ Blog: http://www.ArtInNaturePhotography.com/wordpress/ http://www.artinnaturephotography.com/wordpress/