svg output of mesh


352
views
0
12 months ago by
I would like to save a mesh in svg just for quick visualization. When I do this and try to open the svg file, then it does not display the mesh.

n = 10
mesh = UnitSquareMesh(n,n)
File('mesh.svg') << mesh

If there a way to directly save mesh in some format like ps, pdf, png, etc. for quick visualization.
Community: FEniCS Project

3 Answers


2
12 months ago by
from fenics import *
import matplotlib.pyplot as plt

N = 10
mesh = UnitSquareMesh(N, N)

plot(mesh)
plt.show()
plt.savefig('mesh.png')​
0
12 months ago by
See https://fenicsproject.org/qa/3522/how-to-plot-directly-to-file-without-opening-a-window
You can also use write_pdf or write_ps istead of write_png.
written 12 months ago by Adam Janecka  
Doing

fig = plot(mesh, interactive=False)
fig.write_png('mesh.png')

gives error


Traceback (most recent call last):
  File "test_adapt.py", line 23, in <module>
    fig.write_png('mesh.png')
AttributeError: 'list' object has no attribute 'write_png'
written 12 months ago by Praveen C  
2
My bad, I just tested it in the old 1.6.0 version where it worked. In the 2016.2 version in Docker, I'm able to save the mesh using
from fenics import *
import matplotlib.pyplot as plt

N = 10
mesh = UnitSquareMesh(N, N)

plot(mesh)
plt.show()
plt.savefig('mesh.png')​
written 12 months ago by Adam Janecka  
Great. Can you make this into an answer so I can accept it.
written 12 months ago by Praveen C  
0
9 weeks ago by
Val K.  
Hello, unfortunately the way with plt.savefig(), does no work for me. The output file in png format that is generated does not show the mesh , it's just a blank figure.
I would like to iterate over a mesh, and for different displacement on boundary, plot the resulted mesh. However, neither plt.savefif() nor fig.write_png("mesh") work correctly.
In addition, in each iteration it is impossible to keep the figure closed, i.e. not to appear on screen.

If there is any other way to save a figure in .png format , and in addition not to show the figure on each iteration, I would be very grateful if you could share it with me.
Thank you all in advance.
Please login to add an answer/comment or follow this question.

Similar posts:
Search »