GithubHelp home page GithubHelp logo

Comments (6)

banesullivan avatar banesullivan commented on June 19, 2024

Hi @laserman781 - this question is more appropriate for the pyvista-support repository, so I am moving it there shortly.

The code you have looks appropriate for plotting a PolyLine - using pv.Spline is the right choice. Unfortunately, there isn't much more I can offer without seeing visualizations of why the spline is not what you want or without having the csv file you read.

My guess is that the Spline looks wacky because the points in your csv file are not ordered - you'll likely need to make sure the points are ordered for the PolyLine/Spline to work.

from pyvista-support.

laserman781 avatar laserman781 commented on June 19, 2024

@banesullivan The spline comes out correctly with pv.Spline, although I want to avoid the interpolation of spline. Any suggestions?

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Ah yes, the Spline is parametric and interpolates the points which might not be desired.

Try this solution with lines_from_points():

import pyvista as pv
import numpy as np
pv.set_plot_theme('doc')

def make_points():
    """Helper to make XYZ points"""
    theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
    z = np.linspace(-2, 2, 100)
    r = z**2 + 1
    x = r * np.sin(theta)
    y = r * np.cos(theta)
    return np.column_stack((x, y, z))


def lines_from_points(points):
    """Given an array of points, make a line set"""
    poly = pv.PolyData()
    poly.points = points
    cells = np.full((len(points)-1, 3), 2, dtype=np.int)
    cells[:, 1] = np.arange(0, len(points)-1, dtype=np.int)
    cells[:, 2] = np.arange(1, len(points), dtype=np.int)
    poly.lines = cells
    return poly

points = make_points()

line = lines_from_points(points)

p = pv.Plotter()
p.add_mesh(points, color='red')
p.add_mesh(line, color='blue',)
p.show()

download

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Also, note that a very similar function exists in PyVista: https://docs.pyvista.org/utilities/utilities.html#pyvista.lines_from_points

However, it requires the points array to be explicit about which lines make each segment - if the points are already ordered, then you can probably stick with the method I shared in the post above.

from pyvista-support.

laserman781 avatar laserman781 commented on June 19, 2024

@banesullivan This is excellent information thank you!

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

I'm assuming this solution worked? If so, would you please close the issue?

from pyvista-support.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.