How to add a geomdl NURBS curve to an existing axis?

223 views Asked by At

I'm trying to work with NURBS using geomdl. I already have an matplotib axis, where several elements are plotted using:

  • plot()
  • scatter()
  • imshow() (for Background image)
  • add_patch

The result looks like this: https://i.stack.imgur.com/vNMYj.png

Now I want to plot a NURBS curve with geomdl.

This code

from geomdl import BSpline
from geomdl.visualization import VisMPL
crv = BSpline.Curve()
crv.degree = 2
crv.ctrlpts = [[1, 0, 0], [1, 1, 0], [0, 1, 0]]
crv.knotvector = [0, 0, 0, 1, 1, 1]
vis_config = VisMPL.VisConfig(legend=False, axes=False, figure_dpi=120, ctrlpts=False, evalpts=True)
vis_obj = VisMPL.VisCurve2D(vis_config)
crv.vis = vis_obj
crv.render()

lets me display a NURBS curve. But it appears in a separate window. How can I plot in the existing axis/figure as shown in my screenshot?

1

There are 1 answers

0
dysentrieb On

I was blind. The solution is easy, I think:

points = crv.evalpts                     # this gives a list of x, y coordinates of
                                         # the NURBS curve. These can be fed to an
                                         # axis
x, y = zip(*list(points))
axis.plot(x, y)