简体   繁体   中英

(Python) Plotting pressure as function of X,Y,Z

Basically, I am trying to plot pressure as function of X,Y,Z. Can any one give me an example on how to do it?

Some additional information:

X,Y,Z represent position in the domain;

Pressure represent the intensity

I am retrieving the dataset from a FILE HDF5.

len(X) = 10
len(Y) = 1
len(Z) = 636

Thanks in advance

UPDATE:

Here is my initial piece of code that retrieves the data

import h5py

FILE_INPUT = "../output/hdf5/Diagramme_rayonnement_3D.h5"
DATASET_NAME = "/dset"
ATTRIBUTE_NAME = "Calculation Attributes"

file = h5py.File(FILE_INPUT)
dset = file[DATASET_NAME]
attr = dset.attrs[ATTRIBUTE_NAME]
attr = {'Nx': attr[0], 'Ny': attr[1], 'Nz': attr[2], 'Nfreq': attr[3], 'deltaX': attr[4], 
        'deltaY': attr[5], 'deltaZ': attr[6], 'deltaF': attr[7], 'Fmin': attr[8]}

X = [x * attr['deltaX'] for x in range(int(attr['Nx']))]
Y = [y * attr['deltaY'] for y in range(int(attr['Ny']))]
Z = [z * attr['deltaZ'] for z in range(int(attr['Nz']))]
Frequencies = [freq * attr['deltaF'] for freq in range(int(attr['Nfreq']))]
Frequencies += attr['Fmin']

As you can see, I have this dataset that I need to plot which is a 4D array. The first index refers to the Frequency. The second, third and forth index refer to position in the domain. And the value stored represent the pressure(Intensity). What I need to do is to create a GUI that exhibits the plot by frequency. So we are left with a 3D array with a pressure value. Those data are being generated by a C/C++ code. So depending on the config file, the values may change.

I left len(Y) = 1 on purpose to speed up the results.

I have no idea on where to start. Can you please guide me.

PS: I would really prefere to use VTK solution. But it is not necessarily a constraint.

For the plotting part: https://plot.ly/python/3d-wireframe-plots/

import plotly.plotly as py
import plotly.graph_objs as go

import numpy as np

# Creating the data
x = np.linspace(-5, 5, 50)
y = np.linspace(-5, 5, 50)
xGrid, yGrid = np.meshgrid(y, x)
R = np.sqrt(xGrid ** 2 + yGrid ** 2)
z = np.sin(R)

# Creating the plot
lines = []
line_marker = dict(color='#0066FF', width=2)
for i, j, k in zip(xGrid, yGrid, z):
    lines.append(go.Scatter3d(x=i, y=j, z=k, mode='lines', line=line_marker))

layout = go.Layout(
    title='Wireframe Plot',
    scene=dict(
        xaxis=dict(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        yaxis=dict(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        zaxis=dict(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        )
    ),
    showlegend=False,
)
fig = go.Figure(data=lines, layout=layout)
plot_url = py.plot(fig, filename='wireframe_plot')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM