Multiply two probability plots (CDF/PDF)
4 comentarios
Respuesta aceptada
Hi @Deepayan Bhadra,
You mentioned, “How can I multiply these plots to convey a (qualitative) idea? “
Please see my response to your comments below.
My suggestion to achieve your goal of combining these two plots while maintaining clarity would be overlaying them in a single figure. This would allow you to visualize both the cumulative probabilities and the density of occurrences simultaneously. After analyzing your code, here is example code snippet to help you out.
% Generate some generic data for demonstration data = randn(1000, 1); % Normal distributed data
% Create CDF plot figure(); ax1 = subplot(1,1,1); cdfplot(data); hold on;
% Fit a normal distribution to the data pd = fitdist(data,'Normal');
% Generate x values for PDF x_values = linspace(min(data), max(data), 100); y_values = pdf(pd, x_values);
% Plot PDF on the same axes plot(x_values, y_values, 'r-', 'LineWidth', 2);
% Reverse x-axis and set log scale for y-axis ax1.XDir = 'reverse'; set(gca, 'YScale', 'log');
% Add legends and labels legend('CDF', 'PDF'); xlabel('Value'); ylabel('Probability'); title('Combined CDF and PDF Plot'); hold off;
So, in above example code, I used randn(1000, 1) to create a sample dataset that follows a normal distribution. The cdfplot(data) function creates the cumulative distribution function plot. You will see that the example code fits a normal distribution to the data and calculates its PDF over a range of x-values. The hold on command allows you to overlay the PDF plot on top of the CDF plot in the same figure and the x-axis is reversed, for more information on this command, please refer to
https://www.mathworks.com/help/matlab/ref/hold.html#
and a logarithmic scale is applied to the y-axis for better visibility of both plots. Make sure when you visualize both plots together, see how the probability density (PDF) at each point contributes to the cumulative probability (CDF). This dual representation will help you understanding both local behavior (PDF) and global behavior (CDF) of your data distribution. Feel free to adjust line styles, colors, and markers according to your preferences for better visual distinction between CDF and PDF.
Please see attached.
If you have any further questions, please let me know.
11 comentarios
Hi @ Deepayan Bhadra,
After reviewing your comments second time, I do apologize for misunderstanding your comments. I have edited comments in above post. Your goal is to visualize how the values in vector a correspond to the ranges of values in vector b, specifically showing high probabilities within a certain range of b. Also, you want to represent discrete probabilities derived from two vectors, where:
- Vector a contains probability values.
- Vector b defines corresponding ranges.
In your given example, you are interested in showing that a value in vector b between -90 and -70 corresponds to a high probability from vector a. You already defined the data by representing them in two vectors:
a = [70, 23, 3, 0, 0, 0, 0, 0, 0, 0];
b = [-90, -80, -70, -60, -50, -40, -30, -20, -10, 0];
It will be helpful to normalize your probabilities so that they sum to 1 if you are treating them as probabilities. In this case:
total_probability = sum(a); normalized_a = a / total_probability; % Normalize 'a'
Then use a bar plot to represent the probabilities clearly. Here’s how you can implement this in MATLAB:
% Create the bar plot for probabilities figure(); bar(b, normalized_a); % Use 'b' for x-axis and normalized probabilities for y-axis xlabel('Value (b)'); ylabel('Probability'); title('Discrete Probability Distribution');
% Highlight the range of interest hold on; xline(-90,'r--','Start Range','LabelHorizontalAlignment','left'); xline(-70,'g--','End Range','LabelHorizontalAlignment','right');
% Customize y-axis limits if necessary ylim([0 max(normalized_a) * 1.1]);
% Add grid for better visibility grid on;
hold off;
As you can see in example code snippet, the bar function creates a bar plot where each bar represents the probability associated with each value in vector b. The xline function is used to add vertical lines at -90 and -70 to visually indicate the range of interest and normalization makes sure that your representation is consistent with probability principles. Finally, grid enhances readability by allowing viewers to gauge values more easily. This visualization will clearly show that values in vector a corresponding to b values between -90 and -70 are significantly higher than those outside this range. This can be crucial for interpreting data distributions or making decisions based on these probabilities.
Hope this answers your question. If you have further questions or need additional modifications, feel free to ask!
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!