svg output of mesh


124
views
0
4 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

2 Answers


2
4 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
4 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 4 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 4 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 4 months ago by Adam Janecka  
Great. Can you make this into an answer so I can accept it.
written 4 months ago by Praveen C  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »