Open forbonder opened 3 years ago
This isn't perfect, mostly because delanuay_2d
would create a smoother mesh with a bounding line, but it works. Approach is:
PolyData
from it.import numpy as np
import pandas as pd
import pyvista as pv
u = pd.read_csv('u.csv')
domains = pd.read_csv("domain.csv")
u1 = u.iloc[0:735,0].values
u2 = u.iloc[0:2161,1].values
d1 = domains.iloc[0:735,0:2].values
d2 = domains.iloc[0:2161,2:4].values
flower_pts = pv.PolyData(np.hstack((d1, u1.reshape(-1, 1))))
surf_pts = pv.PolyData(np.hstack((d2, u2.reshape(-1, 1))))
# point plot
pl = pv.Plotter()
pl.add_mesh(flower_pts, color='y', smooth_shading=True)
pl.add_mesh(surf_pts, color='orange')
# pl.camera_position = 'xy'
pl.show()
# mesh plot
flower_mesh = flower_pts.delaunay_2d(alpha=0.1)
surf_mesh = surf_pts.delaunay_2d(alpha=0.08)
pl = pv.Plotter()
pl.add_mesh(flower_mesh, color='y', smooth_shading=True)
pl.add_mesh(surf_mesh, color='orange')
pl.show()
Save as a pdf screenshot with:
pl = pv.Plotter()
pl.add_mesh(flower_mesh, color='y', smooth_shading=True)
pl.add_mesh(surf_mesh, color='orange')
pl.show(auto_close=False)
pl.save_graphic('flower_power.pdf')
pl.close()
Thank you for your reply. However when I tried to save as pdf a blank pdf file is created. Any idea on how to fix that? My system info is as follows
OS : Linux
CPU(s) : 12
Machine : x86_64
Architecture : 64bit
RAM : 15.5 GB
Environment : Jupyter
GPU Vendor : Intel
GPU Renderer : Mesa Intel(R) UHD Graphics 630 (CFL GT2)
GPU Version : 4.6 (Core Profile) Mesa 20.1.8
Python 3.8.3 | packaged by conda-forge | (default, Jun 1 2020, 17:43:00) [GCC 7.5.0]
pyvista : 0.26.1
vtk : 9.0.1
numpy : 1.19.1
imageio : 2.9.0
appdirs : 1.4.4
scooby : 0.5.6
meshio : 4.3.2
matplotlib : 3.3.1
PyQt5 : 5.12.3
IPython : 7.18.1
scipy : 1.5.2
tqdm : 4.50.2
Intel(R) Math Kernel Library Version 2019.0.4 Product Build 20190411 for Intel(R) 64 architecture applications
Description
I have a set of coordinates in 2D (x,y), and corresponding value u. I want to create a surface plot from these data and if possible save it as .eps or .pdf. Here are my codes in Python for scatter plot of the data.
I am completely new to PyVista Is it possible to transform this concavely shaped scatter plot to a surface plot with pyvista?
Example Data
Data for scatter plot data.zip