Plot

The plot module aims to provide a consistent interface to various plotting backends. At this point matplotlib and vtk are supported.

class nutils.plot.BasePlot(name=None, ndigits=0, index=None)[source]

base class for plotting objects

class nutils.plot.PyPlot(name=None, imgtype=None, ndigits=3, index=None, **kwargs)[source]

matplotlib figure

close()[source]

close figure

save(name=None, index=None, **kwargs)[source]

save images

segments(points, color='black', **kwargs)[source]

plot line

mesh(points, values=None, edgecolors='k', edgewidth=0.1, mergetol=0, setxylim=True, aspect='equal', tight=True, **kwargs)[source]

plot elemtwise mesh

polycol(verts, facecolors='none', **kwargs)[source]

add polycollection

slope_marker(x, y, slope=None, width=0.2, xoffset=0, yoffset=0.2, color='0.5')[source]

slope marker

slope_triangle(x, y, fillcolor='0.9', edgecolor='k', xoffset=0, yoffset=0.1, slopefmt='{0:.1f}')[source]

Draw slope triangle for supplied y(x) - x, y: coordinates - xoffset, yoffset: distance graph & triangle (points) - fillcolor, edgecolor: triangle style - slopefmt: format string for slope number

slope_trend(x, y, lt='k-', xoffset=0.1, slopefmt='{0:.1f}')[source]

Draw slope triangle for supplied y(x) - x, y: coordinates - slopefmt: format string for slope number

rectangle(x0, w, h, fc='none', ec='none', **kwargs)[source]
griddata(xlim, ylim, data)[source]

plot griddata

cspy(A, **kwargs)[source]

Like pyplot.spy, but coloring acc to 10^log of absolute values, where [0, inf, nan] show up in blue.

class nutils.plot.PyPlotVideo(name, videotype=None, clearfigure=True, framerate=24)[source]

matplotlib based video generator

Video generator based on matplotlib figures. Follows the same syntax as PyPlot.

Parameters:
  • clearfigure (bool, default: True) – If True clears the matplotlib figure after writing each frame.
  • framerate (int, float, default: 24) – Framerate in frames per second of the generated video.
  • videotype (str, default: ‘webm’ unless overriden by property videotype) – Video type of the generated video. Note that not every video type supports playback before the video has been finalized, i.e. before close has been called.
  • properties (Nutils) –
  • -----------------
  • videotype – see parameter with the same name
  • videoencoder (str, default: 'ffmpeg') – Name or path of the video encoder. The video encoder should take the same arguments as ‘ffmpeg’.

Examples

Using a with-statement:

video = PyPlotVideo('video')
for timestep in timesteps:
  ...
  with video:
    video.plot(...)
    video.title('frame {:04d}'.format(video.frame))
video.close()

Using saveframe:

video = PyPlotVideo('video')
for timestep in timesteps:
  ...
  video.plot(...)
  video.title('frame {:04d}'.format(video.frame))
  video.saveframe()
video.close()
saveframe()[source]

add a video frame

close()[source]

finalize video

class nutils.plot.DataFile(name=None, index=None, ext='txt', ndigits=0)[source]

data file

class nutils.plot.VTKFile(name=None, index=None, ndigits=0, ascii=False)[source]

vtk file

rectilineargrid(coords)[source]

set rectilinear grid

unstructuredgrid(cellpoints, npars=None)[source]

set unstructured grid

celldataarray(name, data)[source]

add cell array

pointdataarray(name, data)[source]

add cell array

nutils.plot.writevtu(name, topo, coords, pointdata={}, celldata={}, ascii=False, superelements=False, maxrefine=3, ndigits=0, ischeme='gauss1', **kwargs)[source]

write vtu from coords function