Adding a scatter of points to a boxplot (2024)

360 views (last 30 days)

Show older comments

Peyman Obeidy on 29 Apr 2018

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot

Edited: Seth DeLand on 26 May 2022

Accepted Answer: dpb

  • boxplot_inpy.png

Does anyone come with with a code which can match the python generated boxplot?

1 Comment

Show -1 older commentsHide -1 older comments

dpb on 29 Apr 2018

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562297

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562297

Open in MATLAB Online

Presuming the points actually a set of coordinates as shown, don't see why

hold on

scatter(x,y)

with appropriate x,y arrays and the associated color arrays, etc., wouldn't come reasonably close...

Sign in to comment.

Sign in to answer this question.

Accepted Answer

dpb on 29 Apr 2018

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_317801

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_317801

Open in MATLAB Online

Indeed, that seems to work just fine...

load carsmall MPG % the sample dataset variable

hold on

scatter(ones(size(MPG)).*(1+(rand(size(MPG))-0.5)/10),MPG,'r','filled')

yields

Adding a scatter of points to a boxplot (4)

It's possible to add color with value scaling in scatter see the details on it for all the particulars.

5 Comments

Show 3 older commentsHide 3 older comments

Peyman Obeidy on 30 Apr 2018

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562422

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562422

Open in MATLAB Online

Here is the same thing with a bit more manipulations

load carsmall MPG % the sample dataset variable

MPG(:,2)=MPG(:,1).*2;

MPG(:,3)=MPG(:,1).*3;

boxplot(MPG,'Notch','on','Labels',{'mu = 5','mu = 6','mu = 6'},'Whisker',1)

lines = findobj(gcf, 'type', 'line', 'Tag', 'Median');

set(lines, 'Color', 'g');

% Change the boxplot color from blue to green

a = get(get(gca,'children'),'children'); % Get the handles of all the objects

%t = get(a,'tag'); % List the names of all the objects

%box1 = a(7); % The 7th object is the first box

set(a, 'Color', 'r'); % Set the color of the first box to green

hold on

x=ones(length(MPG)).*(1+(rand(length(MPG))-0.5)/5);

x1=ones(length(MPG)).*(1+(rand(length(MPG))-0.5)/10);

x2=ones(length(MPG)).*(1+(rand(length(MPG))-0.5)/15);

f1=scatter(x(:,1),MPG(:,1),'k','filled');f1.MarkerFaceAlpha = 0.4;hold on

f2=scatter(x1(:,2).*2,MPG(:,2),'k','filled');f2.MarkerFaceAlpha = f1.MarkerFaceAlpha;hold on

f3=scatter(x2(:,3).*3,MPG(:,3),'k','filled');f3.MarkerFaceAlpha = f1.MarkerFaceAlpha;hold on

Adding a scatter of points to a boxplot (6)

dpb on 30 Apr 2018

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562430

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562430

Nice choices..looks good. :)

Peyman Obeidy on 30 Apr 2018

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562432

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562432

Thank you

Rubina Chandnani on 22 Jul 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_1650424

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_1650424

In the line of code in scatter, is there a way to use a different color using uisetcolor? (I don't want to use the default colors).

Seth DeLand on 26 May 2022

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_2180020

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_2180020

Edited: Seth DeLand on 26 May 2022

Open in MATLAB Online

I'd like to add that there is now an easier way to do this with boxchart (added in R2020a) and swarmchart (added in R2020b):

load carsmall MPG % the sample dataset variable

MPG(:,2)=MPG(:,1).*2;

MPG(:,3)=MPG(:,1).*3;

boxchart(MPG)

hold on

x = repmat(1:3,100,1); % create the x data needed to overlay the swarmchart on the boxchart

swarmchart(x,MPG,[],'red')

Adding a scatter of points to a boxplot (11)

Sign in to comment.

More Answers (2)

Hassan on 18 May 2019

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_375615

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_375615

Open in MATLAB Online

Hi, here you can find a one line solution for the jitter like function using the 'undocumented matlab' features.

load carsmall MPG

figure;

MPG(:,2)=MPG(:,1).*2;

MPG(:,3)=MPG(:,1).*3;

boxplot(MPG);

hold on;

x=repmat(1:3,length(MPG),1);

scatter(x(:),MPG(:),'filled','MarkerFaceAlpha',0.6','jitter','on','jitterAmount',0.15);

Best, HM

1 Comment

Show -1 older commentsHide -1 older comments

Junru Ruan on 13 Dec 2019

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_777810

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_777810

Open in MATLAB Online

This is the best answer! very nice presentation.

Tips: if you used group in box plot, do a 'unique' to get the right x axis.

boxplot(report_table.data,report_table.group_id);

hold on

[C, ~, ic]= unique([report_table.group_id],'stable');

scatter(ic,report_table.data,'filled','MarkerFaceAlpha',0.6','jitter','on','jitterAmount',0.15);

xlabel('Group ID');

ylabel('Data');

hold off

Sign in to comment.

Ernesto Salcedo on 27 Nov 2020

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_557928

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_557928

Edited: Ernesto Salcedo on 27 Nov 2020

Open in MATLAB Online

Boxchart solution for grouped categorical data

Table with random group

count = 20;

T = table(randi(10,count,1), categorical(repmat(["papaya";"silicon"], count/2,1)),'VariableNames',["Recharges","model"])

T.idx = grp2idx(T.model); % convert categories into group indices

Boxchart

figure

hc = boxchart(T.idx, T.Recharges); % group by index

hold on

% overlay the scatter plots

for n=1:max(unique(T.idx))

hs = scatter(ones(sum(T.idx==n),1) + n-1, T.Recharges(T.idx == n),"filled",'jitter','on','JitterAmount',0.1);

hs.MarkerFaceAlpha = 0.5;

end

set(gca,"XTick", unique(T.idx),"XTickLabel",categories(T.model))

Adding a scatter of points to a boxplot (15)

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsData Distribution PlotsScatter Plots

Find more on Scatter Plots in Help Center and File Exchange

Tags

  • scatter
  • boxplot

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.


Adding a scatter of points to a boxplot (16)

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

Adding a scatter of points to a boxplot (2024)

FAQs

How many data points do you need for a Boxplot? ›

A boxplot works best when the sample size is at least 20. If the sample size is too small, the quartiles and outliers shown by the boxplot may not be meaningful. If the sample size is less than 20, consider using an Individual value plot instead.

When to use scatter plot vs boxplot? ›

Scatter plots, to show relationships among numerical variables. Line graphs, to show change over time. Histograms, to show data distributions. Boxplots, to show between-group and within-group variation.

How do you increase the size of a scatter plot? ›

One way to adjust the marker size in a scatter plot is by using the 's' parameter in the plt. scatter() function. The 's' parameter allows you to specify the size of the markers in points. In this example, we have defined three lists: 'x', 'y', and 'marker_size'.

How do you plot multiple scatter plots? ›

Creating multiple plots on a single figure
  1. import matplotlib.pyplot as plt fig = plt. figure() We are going to create 2 scatter plots on the same figure. ...
  2. ax1 = fig. add_subplot(121) ax2 = fig. ...
  3. import numpy as np data_1=np. array(np. ...
  4. ax1. scatter(data_1[:,0],data_1[:,1]) ax2. ...
  5. ax1. set_title('data 1') ax1. ...
  6. plt. show()

How many data points do you need for a scatter plot? ›

You will need at least 50-100 paired samples of data that you think might be related for a scatter plot. Enter the data into a spreadsheet, and plot the data points on a diagram (if you have created your spreadsheet in MS Excel, you can use the program to build a scatter plot with your data).

What is the minimum number of samples for a box plot? ›

Whereas histograms require a sample size of at least 30 to be useful, box plots require a sample size of only 5, provide more detail in the tails of the distribution and are more readily compared across three or more samples.

When not to use a scatter plot? ›

Too little or too much: Try not to use a scatter plot when you either have very few data points, or a large number of data points.

How do you know when to use a scatter plot? ›

Use a scatter plot when you have two variables that pair well together. If you have two variables that pair well together, plotting them on a scatter diagram is a great way to view their relationship and see if it's a positive or negative correlation.

When should you use a scatter plot to show data for a project? ›

Scatter plots' primary uses are to observe and show relationships between two numeric variables. The dots in a scatter plot not only report the values of individual data points, but also patterns when the data are taken as a whole. Identification of correlational relationships are common with scatter plots.

What is a good sample size for a scatter plot? ›

Although there are no formal guidelines for the amount of data needed for a scatterplot, larger samples more clearly indicate patterns in the data. A scatterplot that has a fitted regression line is most effective when the sample size is approximately 40 or greater.

What makes a good scatter plot? ›

They're easy to read. The use of dots makes scatter plots easier to read. To increase readability, you can also draw a line through the middle of the graph to demonstrate a positive or negative correlation.

How can a scatter plot be improved? ›

One way is to very slightly nudge each data point away from the cluster center by manually moving the point. Another way is to make the fill colour of each point slightly transparent and change the border colour of all data points in the scatterplot so they stand out against one another better.

What is an alternative to a scatter plot? ›

Dot plot. It serves as a valuable alternative to a scatter plot when you want to show a range of values associated with each category – connectors will help with that.

How to make a scatter plot with two sets of data? ›

Highlight the two columns you want to include in your scatter plot. Then, go to the “Insert” tab of your Excel menu bar and click on the scatter plot icon in the “Recommended Charts” area of your ribbon. Select “Scatter” from the options in the “Recommended Charts” section of your ribbon.

How to explain a scatter plot? ›

A scatterplot shows the relationship between two quantitative variables measured for the same individuals. The values of one variable appear on the horizontal axis, and the values of the other variable appear on the vertical axis. Each individual in the data appears as a point on the graph.

How many values do we need to construct a box plot? ›

A box plot is constructed from five values: the minimum value, the first quartile, the median, the third quartile, and the maximum value. We use these values to compare how close other data values are to them.

How many numbers do you need to make a box plot? ›

A box and whisker plot—also called a box plot—displays the five-number summary of a set of data. The five-number summary is the minimum, first quartile, median, third quartile, and maximum.

What is 50 of the data in a box plot? ›

Interpreting a boxplot can be done once you understand what the different lines mean on a box and whisker diagram. The line splitting the box in two represents the median value. This shows that 50 % of the data lies on the left hand side of the median value and 50 % lies on the right hand side.

How much data is in the box portion of the Boxplot? ›

The box is used to represent the interquartile range (IQR) — or the 50 percent of data points lying above the first quartile and below the third quartile — in the given data set.

References

Top Articles
Eight Great Meal in a Jar Recipes - Make-Ahead Meal Mom
41 Easy Vegan Meal Prep Recipes for the Week
The Advantages of Secure Single Sign-on on the BenQ Board
Monitor por computador e pc
Craigslist Kentucky Cars And Trucks - By Owner
Booked On The Bayou Houma 2023
T800 Kenworth Fuse Box Diagram
Steve Wallis Wife Age
Panorama Charter Portal
Feliz Domingo Bendiciones, Mensajes cristianos para compartir | Todo imágenes
What You Need to Know About County Jails
Triple the Potatoes: A Farmer's Guide to Bountiful Harvests
Maine Coon And Bobcat Mix
Hannaford Weekly Flyer Manchester Nh
Shahala Middle School Shahala Middle School Student Handbook
Naughty Neighbor Tumblr
Calculator Souo
Metalico Sharon Pa
Sunday Td Bank
5162635626
Mhrb Near Me
Optum Primary Care - Winter Park Aloma
Sophia Garapetian Twitter
James And Lisa Goy Obituary
Smile 2022 Showtimes Near Savoy 16
Vioc Credit Card Charge
Gay Cest Com
Reptile Expo Spokane
Pella Culver's Flavor Of The Day
16 Things to Do in Los Alamos (+ Tips For Your Visit)
They Cloned Tyrone Showtimes Near Showbiz Cinemas - Kingwood
Small Party Hall Near Me
charleston rooms & shares - craigslist
Broussard’s Mortuary Major Dr.
Fuzz Bugs Factory Hop Halloween
Kpq News Wenatchee Washington
R/Moissanite
Bfads 2022 Walmart
Stephanie Ruhle's Husband
Dollar Tree Aktie (DLTR) • US2567461080
Moviesverse 2023
Montefiore Email Outlook Login
Weather Underground Pewaukee
Baroque Violin Shop Cincinnati Oh
The Spot Barbershop - Coconut Creek Reviews
Nailery Open Near Me
Melissa Bley Ken Griffin
Empire Of Light Showtimes Near Santikos Entertainment Palladium
Immortal Ink Waxahachie
Dungeon Family Strain Leafly
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 6808

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.