Use Patch to use Z as color over depth

2 次查看(过去 30 天)
Hello,
I'm trying to visualize measurements
I have 23 datasets about flow between 1 and 8 meter depth. each dataset (measured by ADCP) has a size of 507000 x 3, containing time (x), constant depth (y) and measured data (c) in which values are between [-1 and 1]. The dataset nr. 20 - 23 are a bit shorter [1x145540], visible in the bottom of the plot. All data for z plotted as color should vary strongly. I have set up 23 y lines over the corresponding depth with time (i.e. an XY field) , where the color varies with the flow speed measured. see figure.
Sometimes Patch does a great job, where the measurements are patched in this graph showing the variability over time. Other times it seems like Patch neglects the strong variation and interpolates between the first and last value in the dataset. The proper variation in the dataset is visible in the in the bottom 3 lines and near the top in the 2nd line. I tried to shortern the other datasets to the same length, though this aslo does not result in the proper visualisation.
Does anyone have experience with this, know how to fix this, or have other ways to properly visualize these datasets? Contour doesn't work as creating a XY field with the accompanied data creates a dataset which is to large handle for matlab. also computation time becomes very slow.
And i know i shouldn't use eval, but seemed the quicked way for preparing and plotting data ;).
for i = 1:23
eval(sprintf('x.x%d = depth.d%d(:,1)',i,i)) % time
eval(sprintf('y.y%d = depth.d%d (1,2)*ones(length(depth.d%d (:,1)),1)',i,i,i)) % stored depth
eval(sprintf('c.c%d = depth.d%d (:,4)',i,i)) % the variables of interest to plot as colour within line
end
%%
PlotPeriod = [datenum('25-06-2020 07:00:00', 'dd-mm-yyyy HH:MM:SS') datenum('03-07-2020 15:00:00', 'dd-mm-yyyy HH:MM:SS')]
xData10=linspace(PlotPeriod(1), PlotPeriod(2),10);% %bepalen van dateticks
p_patch=figure; hold
title('\rm North velocity','FontSize', 9)
for i=1:5
eval(sprintf( 'p(%d) = patch(x_ADCP_avg.x%d, y_ADCP_avg.y%d, c_err_ACDP_avg.c%d,''EdgeColor'',''interp'',''LineStyle'',''-'',''MarkerFaceColor'',''none'')',i,i,i,i)) ;
end
for i=1:5
p(i).LineWidth=15
end
set(gca, 'YDir','reverse')
cb = colorbar('north', 'AxisLocation', 'in');
cb.Position= [0.148454746131228,0.0205,0.739514348791510,0.0155608465608466]
p_patch.CurrentAxes.CLim=[-.15 .15]
ylabel('Depth (m)')
xlabel('Tijd')
ax10=gca;
ax10.XTick = xData10; %geef aan waar ticks komen
datetick(ax10,'x',1,'keepticks')
xlim([PlotPeriod(1) PlotPeriod(2)]);
ylim([1.8 8.9])

回答(1 个)

Raag
Raag 2025-2-23
Hi bas,
The challenge you're facing is common when dealing with large datasets, especially when visualizing data with varying intensities. To address your issue, you may consider the following approaches:
You can use a line-per-depth with colour mapped to your measured data. Since each of your 23 ADCP datasets is essentially a time-series at a constant depth, you can visualize them by plotting 23 coloured lines, one for each depth.
You can either use scatter to plot ‘time vs depth’, colouring each point by the flow value which will give you a discrete set of markers that are coloured according to your flow values:
scatter(time_i, depth_i, 10, flow_i, 'filled');
colormap(jet);
colorbar;
Or you can create a vertical surface in time-depth space, and apply colour from your measurements which will build a vertical ‘ribbon’ for each depth, allowing smooth colour transitions:
Tsurf = [time_i(:) time_i(:)];
Dsurf = [depth_i(:) (depth_i(:) + 0.05)];
Csurf = [flow_i(:) flow_i(:)];
surf(Tsurf, Dsurf, zeros(size(Tsurf)), Csurf, ...
'EdgeColor','interp','FaceColor','none');
If you want a 2D colour map, define a common time vector covering the entire span at your desired resolution. Define a vector of depths covering 1 to 8 meters and then interpolate each dataset onto this uniform grid:
imagesc(TimeVec, DepthVec, Cmat.');
set(gca, 'YDir', 'normal');
colormap(jet);
colorbar;
As you mentioned, the 'patch' function sometimes fails to capture the strong variations in your dataset. This happens because patch is designed for polygon-based plotting, which can lead to interpolation across large datasets, thereby smoothing out the details. This behaviour results in the loss of the intermediate variations you observed. To better capture the nuances in your data, consider using 'scatter', 'line', or 'surface plots'. These methods are more suited for line data and provide a more accurate representation of your flow measurements by preserving the detail of each data point.
For a better understanding of the above solution, refer to the following MATLAB documentations:

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by