I have quite a large data set that I want to visulaise by overlaying all the traces on one plot, with the traces only using one colour & the opacity/brightness of the resulting trace determined by how many instances of a particular value occur at each point - the only thing I can think to compare it to would be persistence on an old school oscilloscope.
Can someone point me to the correct plot type to achieve this or help me out with some code?
Thanks

5 commentaires

dpb
dpb le 9 Août 2020
Just plot with hold on and selected color to put the points on the screen -- histcounts() will let you bin the observatons by whatever resolution you have to sufficiently have multiple counts; you can set a colormap based on those counts by bin location...
Without trying to make up data...
DrEamonn
DrEamonn le 10 Août 2020
Modifié(e) : DrEamonn le 10 Août 2020
Thanks dpb
The data is just 1000+ similar but slightly different x^2 type traces. I would like to show the bounds of all the data with some sort of highlighted border, & then the range of the data shaded with areas of common data points denser/more opaque thean areas of less occurance - similar to how pulse info is displayed in the Google Fit app.
Adam Danz
Adam Danz le 10 Août 2020
An example image would help.
It sounds like you have you have to compute the outter boundaries of the data and then use patch or fill to plot the shape of the data.
DrEamonn
DrEamonn le 10 Août 2020
This is similar to what I had in mind.
The main difference between the above & what I would like to achieve is that I would like the opacity to vary depending on denisty of values i.e. simialr to an old school oscilloscope display with persistence.
Adam Danz
Adam Danz le 10 Août 2020
Modifié(e) : Adam Danz le 10 Août 2020
As far as I know you cannot vary the transparency within a patch. However, you can adjust the color (ie, shades of blue) and then set a constant transparency value.
Here's some background info on controlling the color transitions of a patch by setting the CData property of a patch object. You can set a colormap from light blue to dark blue.

Connectez-vous pour commenter.

 Réponse acceptée

Star Strider
Star Strider le 10 Août 2020
Perhaps something like this:
x = linspace(0, 10, 250); % Create Data
y = randn(10,1) .* sin(2*pi*x + randn(10,1)); % Create Data
figure
plot(x, y) % Original Waveforms
grid
colMin = min(y);
colMax = max(y);
colMean = mean(y);
figure
plot(x, colMean) % Data Mean
hold on
patch([x fliplr(x)], [colMin fliplr(colMax)], 'b', 'FaceAlpha',0.2, 'EdgeColor','none') % Shaded Range
hold off
grid
producing:
This can likely be changed to show other results.
.

10 commentaires

DrEamonn
DrEamonn le 10 Août 2020
That's sooo close to what I'm looking for.
Is there a way of applying a colormap or contour to the patch based on data density?
dpb
dpb le 10 Août 2020
Yeah, but you've got to develop a density variable similarly to how I described earlier to use as the variate.
Try this:
x = linspace(0, 10, 250); % Create Data
y = randn(10,1) .* sin(2*pi*x + randn(10,1)); % Create Data
figure
plot(x, y) % Original Waveforms
grid
colMin = min(y);
colMax = max(y);
colMean = mean(y);
colStd = std(y);
stdMult = (-3:0.5:3);
colData = colMean + stdMult(:)*colStd;
figure
klen = numel(stdMult);
hold on
for k = 1:size(colData,1)
FaceAlfa(k) = (1-abs(stdMult(k)/3.1))*0.2; % Alpha Value For This Face
vflip = klen-k+1;
patch([x fliplr(x)], [colData(k,:) fliplr(colData(vflip,:))], 'b', 'FaceAlpha',FaceAlfa(k), 'EdgeColor','none') % Shaded Range
end
plot(x, colMean,'-r') % Data Mean
hold off
grid
producing (for example, since each run is random):
This calculates the standard deviation ‘bands’ (set in ‘stdMult’) and then creates a separate patch object for each one. Here the ‘FaceAlfa’ vector calculates an alpha value for each face, and ‘k’ and ‘vflip’ sets the y-direction boundaries for each face.
.
DrEamonn
DrEamonn le 10 Août 2020
That's exactly what I was look ing for - thanks Star Strider
Star Strider
Star Strider le 10 Août 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
dpb
dpb le 10 Août 2020
Nice thought w/ the std, SS. Maybe if used the positions and values could make into a single patch and then use the std array as CData to get the smooth color gradient?
Star Strider
Star Strider le 10 Août 2020
I explored that, however it wasn’t obvious to me how to make any colour interpolation scheme (including CData and FaceVertexData) work for this plot. So, I went with what I know, and it appears to work reasonably well.
dpb
dpb le 10 Août 2020
Ah. If "wasn't obvious" to you, then it certainly isn't to me! I never could much fathom CData anyways; just thought perhaps you hadn't thought to look--but, that is also not a likely event either. :)
DrEamonn
DrEamonn le 11 Août 2020
I have run some experiements & have a question:
The first plot shows the data plotted using 'plot()'
The second shows the same data plotted using the Start Strider's code:
Why is the highest value on the second plot higher than the first if it is plotted using the same data?
Why is the highest value on the second plot higher than the first if it is plotted using the same data?
My code creates the gradients with reference to the standard deviations of the data, going from -3 to +3, corresponding to probabilities of the data being in that range of 0.0013499 to 0.9986501, so a probability of 0.005 that the data will be included within those limits. If you prefer that they have different limits, set ‘stdMult’ to a different range, perhaps using linspace:
stdMult = linspace(-2, 2, 15);
The limits must be symmetrical, and an odd number of elements appears to work best. You can experiment with and design the probabilities using normcdf (that will produce the associated probabilities from the elements of ‘stdMult’) and norminv (that will produce the limits for ‘stdMult’ from the chosen probability).

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange

Produits

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by