How to create a boxplot from a PDF? (2024)

3 views (last 30 days)

Show older comments

Janett Göhring on 22 Apr 2013

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf

Accepted Answer: Teja Muppirala

Open in MATLAB Online

Hello!

I have a somewhat embarrassing question, but me and my colleagues cannot figure it out since several days. Thinking block ^^ So I would appreciate help!

I have a pdf of my data called pdfxcor (598x1), which resembles a normal distribution when I plot it along a x-axis resembling the molecular weight of my data (called pixelweight (598x1)).

plot(pixelweight,pdfxcor)

boxplot(pdfxcor)

I want to display the distribution as boxplot according to the correct molecular weight.

Thanks for your patience! :)

Jette

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Teja Muppirala on 23 Apr 2013

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#answer_83183

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#answer_83183

Open in MATLAB Online

How about something like this. Generate the CDF from your data as Tom suggested, invert it, use the inverted CDF to generate a bunch of samples that follow your distribution exactly, and send those to BOXPLOT:

%%Just making some data that resembles yours

x = linspace(1000,12000,598);

P = normpdf(x,5800,1800);

figure, plot(x,P), title('PDF');

%%Generate the CDF

C = c*msum(P);

C = C/C(end);

figure, plot(x,C); title('CDF');

%%Sample linearly along the inverse-CDF to get a bunch of points

% that have your same distribution

BigNumber = 100000;

p = interp1(C,x,linspace(C(1),C(end),BigNumber));

figure, hist(p,100); % Confirm p indeed has your distribution

figure ,h = boxplot(p);

delete(findobj(h,'tag','Outliers')) % Hide the outliers

4 Comments

Show 2 older commentsHide 2 older comments

Tom Lane on 23 Apr 2013

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_145017

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_145017

Open in MATLAB Online

I like this idea, but here's a simpler version:

p = ((1:100)/101)'; % prob value to invert

x = [norminv(p,10,2), norminv(p,15,3)]; % invert two distributions

boxplot(x)

Janett Göhring on 23 Apr 2013

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_145046

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_145046

Edited: Janett Göhring on 23 Apr 2013

Hi Teja and Tom,

Both are really nice solutions, but I still run into one problem with my data.

So strangly, the histogram doesn't resemble the pdf plotted against the pixelweigth. I get the same result with the inverted distribution.

thanks for your help!!

Tom Lane on 23 Apr 2013

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_145056

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_145056

It looks like your distribution is not symmetric. The normal distribution is symmetric, so it would not resemble the histogram in that respect.

Janett Göhring on 23 Apr 2013

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_145096

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_145096

Open in MATLAB Online

Hi Tom,

the curve was calculated via a Gaussian fit and is symmetric. The x-axis though is based on data, which was fitted with nlinfit and looks like a logarithmic decay. So, after correction the x-axis is not linear anymore. That's why it is so important to plot the pixelweigth against the pdf, otherwise the distribution is not symmetric anymore.

modelFun = @(p,x) p(1)*exp(p(2)*x);

In between, I calculate start parameters for the fit, which is not important for the example.

Next, I fit the pixel position and the Molecular weight of the DNA standard.

p = nlinfit(positionOfStandard, MWOfStandard, modelFun, paramEstsLin(:,1));

The pixelrange is just the y-length of my image in pixel. Here 1:598

pixelweigth = p(1)*exp(p(2)*pixelrange);

After lots of corrections of the original data I fit a Gauss fit through it and calculate the curve, mean and sigma.

cf3 = fit(pixelweigth',data','gauss1');

pdfxcor = cf3(pixelweigth)

After that I need a representation of the normal distributed data along this specialized x-axis (pixelweigth). But not as a curve ... I was asked to display it as a boxplot. And since it is a normal distribution, I thought it must be possible. But Matlab doesn't give an option in "boxplot" to specify a different axis.

thanks for the help! much appreciated :)

Sign in to comment.

More Answers (1)

Tom Lane on 22 Apr 2013

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#answer_83124

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#answer_83124

The boxplot shows the median, lower quartile, and upper quartile. You may be able to calculate these for your pdf. For example, if you have the pdf as a numeric vector, you might compute c*msum on the vector, then divide by the last value to impose the correct probability normalization, then interpolate.

The boxplot also shows a notion of the range of the data, and sometimes outliers. These are harder to extend to a pdf. You could decide that you want to compute the 1% and 99% points as in the previous paragraph, and use those to represent the end points of the range. You could decide not to show outliers.

Plotting these as lines or points will be relatively simple. It would be more of a challenge to plot them in exactly the way that the boxplot function does.

1 Comment

Show -1 older commentsHide -1 older comments

Janett Göhring on 23 Apr 2013

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_144971

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/73084-how-to-create-a-boxplot-from-a-pdf#comment_144971

Hello Tom, thanks for your answer! Can you explain how to interpolate in this case?

For my problem I created two solutions, but I don't like both.

a) I gauss fit my original data to create the pdf, mean and sigma. Then, I sample with randn (1Mio) & the mean and sigma as parameters. This creates a normal distribution based on my fit which can be plotted via boxplot. Since I already fit my original data with a gaussfit, I am not very interested in the outliers. I just was asked to represent the normal distribution as boxplot for easier comparison of mean and range of data. So, I would feel much better when I wouldn't have to sample a new distribution and of course it takes ages to calculate.

b) I calculate mean and the quartiles of the pdf and extract the respective position from the pixelweigth. Then I draw a barplot(colored for the upper quartile and white for the lower quartile) with error bars. I couldn't make this work, since the pdf is only normally distributed when it is plotted against the pixelweigth.

Bit stuck there ^^ Thanks for your help! Jette

Sign in to comment.

Sign in to answer this question.

See Also

Categories

AI, Data Science, and StatisticsStatistics and Machine Learning ToolboxProbability DistributionsExploration and Visualization

Find more on Exploration and Visualization in Help Center and File Exchange

Tags

  • boxplot
  • plot
  • normal distribution
  • pdf

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How to create a boxplot from a PDF? (9)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

How to create a boxplot from a PDF? (2024)
Top Articles
Chili Lime Shrimp Ramen Noodles
5-Minute Kani Salad {Restaurant Style} - The Big Man's World ®
Navin Dimond Net Worth
Tiffany's Breakfast Portage
Best Places To Get Free Furniture Near Me | Low Income Families
Mimissliza01
Stanford Rival Crossword Clue
Abga Gestation Calculator
Indiana girl set for final surgery 5 years after suffering burns in kitchen accident
Minecraft Jenny Mod Dragon Staff
Pbr Oklahoma Baseball
Editado Como Google Translate
Gay Black Scat
Thothub Alinity
Craigslist Worcester Massachusetts: Your Guide to the City's Premier Marketplace - First Republic Craigslist
9:00 A.m. Cdt
888-490-1703
How To Get Father, Son or Grandmother Tokens in Warframe?
Shahala Middle School Shahala Middle School Student Handbook
Craigslist Free En Dallas Tx
Cuộc thi “Chung tay vì an toàn giao thông” năm 2024
Chula Vista Tv Listings
Www.binghamton Craigslist.com
Hours For Autozone Near Me
Morgan Plus Four 2024 review
With Great Animation Comes Great Music — Spider-Man Across the Spider-Verse Live in Concert | Discover Jersey Arts
Jvid Rina Sauce
Management Trainee: Associate Adjuster - June 2025
Rachel Campos-Duffy - Net Worth, Salary, Age, Height, Bio, Family, Career
02080797947
Gold Bowl Vidalia La Menu
Courtney Callaway Matthew Boynton
Kostenlose Karneval Google Slides Themen & PowerPoint Vorlage
Korslien Auction
Missing 2023 Showtimes Near Golden Ticket Cinemas Dubois 5
Generation Zero beginner’s guide: six indispensable tips to help you survive the robot revolution
Amarillos (FRIED SWEET PLANTAINS) Recipe – Taste Of Cochin
Kurlyrose
Media Press Release | riversideca.gov
Mesmerized Nyt Crossword
Cardholder.bhnincentives.com
Spacebar Counter - Space Bar Clicker Test
‘Covfefe’ tells you all you need to know about Trump | CNN Politics
Margie's Money Saver Hey Dudes
Indium Mod Fabric
Sherlock - Streams, Episodenguide und News zur Serie
Winding Road Ahead for China’s EV Growth
The Little Mermaid (2023) | Rotten Tomatoes
Pinellas Fire Active Calls
Watermelon Cucumber Basil Lemonade - Wine a Little, Cook a Lot
Mike Huckabee Bio, Age, Wife, Fox News, Net Worth, Salary
Akc Eo Tryouts 2022
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 6228

Rating: 4.8 / 5 (58 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.