Someone that can help me with 3D graph?
1 comentario
Respuesta aceptada
Hi @Pablo,
To achieve the desired visualization and reviewing the documentation provided at the link below, please see the code along with a detailed explanation of each section.
https://www.mathworks.com/help/matlab/ref/surfc.html
% Define the data x = [13.6, 11.3, 9.7, 9.3, 10.6, 9.8, 25.6, 28.2, 31.4, 28.2, 28.6, 29.2, 17.9, 16.7, 17.1, 22, 19.3, 17.1, 7.4, 7.6, 7.3, 9.7, 9.6, 15.6, 14.6, 15.8, 15, 13.4]; y = [6.77, 7.2, 6.83, 6.69, 6.76, 6.67, 7.87, 7.87, 7.84, 7.98, 8.33, 7.78, 8.03, 7.99, 8.02, 8, 8.03, 8, 6.68, 6.24, 5.84, 7.26, 6.5, 7.97, 8.24, 8.03, 7.9, 7.97]; z = [2.31, 1.71, 3.52, 2.45, 2.6, 1.89, 4.59, 3.87, 3.47, 2.85, 2.17, 3.47, 6.44, 5.86, 3.91, 5.71, 3, 3.57, 3.1, 3.01, 3.29, 3.8, 2.94, 5.72, 4.26, 4.05, 5.24, 6.55];
% Create a grid for interpolation [xq, yq] = meshgrid(linspace(min(x), max(x), 100), linspace(min(y), max(y), 100)); zq = griddata(x, y, z, xq, yq, 'v4');
% Create the surface plot figure; surfc(xq, yq, zq); xlabel('Temperature (°C)'); ylabel('pH'); zlabel('Log Concentration of Virus (g/L)'); title('3D Surface Plot of Virus Concentration'); colorbar; % Add a color bar
% Adjust surface properties shading interp; % Interpolates colors across the surface alpha(0.7); % Set transparency
% Hold on to add the original data points hold on;
% Plot the original data points as blue dots plot3(x, y, z, 'bo', 'MarkerSize', 8, 'MarkerFaceColor', 'b');
% Release the hold hold off;
% Set view angle for better visualization view(45, 30); % Adjust the view angle for better perspective
Please see attached.
In the above provide code snippet, the original data for temperature (x), pH (y), and log concentration of viruses (z) remains unchanged. This data serves as the foundation for our surface plot. The meshgrid function generates a grid of points over which we will interpolate the z values. The linspace function is used to create evenly spaced values between the minimum and maximum of x and y. The griddata function is employed to interpolate the z values over the grid defined by xq and yq. The method v4 is used for smooth interpolation.The surfc function creates a 3D surface plot. The axes are labeled appropriately, and a color bar is added to indicate the scale of the log concentration. The shading interp command smooths the color transitions across the surface, while alpha(0.7) sets the transparency of the surface, allowing for better visibility of the underlying data points. The hold on command allows us to overlay additional plots on the existing figure. The plot3 function is used to plot the original data points as blue dots (bo), with specified marker size and face color. Finally, the view function is called to set the angle of the 3D plot, enhancing the visual perspective of the data.
If you have any further questions, please let me know.
2 comentarios
Hi @Pablo,
After going through your comments, please see my response below.
Understanding Interpolation with griddata
The griddata function in MATLAB is designed to perform interpolation on scattered data points. It utilizes various methods (such as linear, nearest neighbor, natural neighbor, cubic, and v4) to estimate values at query points based on the known values at sample points. Each method has its characteristics:
Linear and Cubic: These methods create surfaces that can be more sensitive to the arrangement of input data points.
V4 (Biharmonic spline): This method is particularly notable for producing smoother surfaces but may introduce artifacts or overshoots in regions where data density is low.
Convex Hull: Interpolation with griddata is constrained by the convex hull of the sample data. If query points fall outside this region or are poorly represented by nearby sample points, it can lead to extrapolated values or peaks that don't align with the input constraints.
Data Density and Distribution: Sparse or unevenly distributed sample points can lead to misleading interpolated values. If there are few points surrounding certain areas (like your z-values), the algorithm may generate peaks as it tries to smoothly connect these sparse points.
Explanation of Observed Peak at z ≈ 8
The peak you observe at approximately z = 8 could be attributed to several factors:
Interpolation Error: If your data does not adequately cover all regions of interest (especially around the temperatures and pH values you mentioned), the interpolation algorithm may produce exaggerated values as it attempts to create a smooth transition between known data points.
Smoothing Effects: The "v4" method might be overly smoothing your surface, causing it to generate peaks that are not present in the actual dataset. This is particularly true if there are abrupt changes in your data's behavior that are not captured well by surrounding sample points.
Boundary Effects: If the input values for temperature (T) and pH are near the edges of your sampled range, boundary effects could cause unexpected peaks in interpolation results.
My recommendations are listed below.
Check Sample Distribution: Ensure that your sample data covers the entire range of interest uniformly. Consider increasing sample density in regions where you observe anomalies.
Experiment with Different Methods: Try using different interpolation methods available within `griddata`, such as linear or cubic, and compare results to see if they yield more reasonable outputs without unexpected peaks.
Use Visualization Tools: Utilize contour plots or mesh visualizations to better understand how your interpolated surface behaves across different ranges and identify areas where peaks occur relative to your sample data distribution.
Normalize Data: If scaling issues exist between x, y, and z values, consider normalizing your data before performing interpolation to minimize distortion effects.
Investigate Local Behavior: Analyze local neighborhoods around critical query points (like those corresponding to T = 30°C and pH = 6) to understand how nearby samples influence interpolated results.
In nutshell, while interpolation can provide valuable insights from scattered data, it is essential to recognize its limitations and potential for introducing artifacts. Carefully managing sample distribution and choosing appropriate methods will help mitigate issues like unexpected peaks in interpolated surfaces. Further exploration into local variations and thorough testing with various interpolation techniques will enhance your understanding and improve outcomes in future analyses.
Más respuestas (1)
0 comentarios
Ver también
Categorías
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!