Grouping Data for a 3d Scatter Plot (2024)

81 views (last 30 days)

Show older comments

John Clarke on 24 Jun 2015

  • Link

    Direct link to this question

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot

  • Link

    Direct link to this question

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot

Commented: Christina Rigsby on 8 May 2022

I have my data in several groups and I want to do a 3d scatter plot where each group has a different colored marker to represent it, say its a dot. I would like group A1 to be red, group A2 to be blue group A3 to be purple etc.

What I do not want is to scale color by one of the factors which it seems to be very happy to do and is completely useless.

Unfortunately this seems to be the most difficult thing possible to do in Matlab. I don't want to learn how to code I just want to do it through the interface and it seems to be impossible, I've wasted an entire afternoon on this.

If someone can throw me a lifeline I'd really appreciate it.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (4)

Chad Greene on 24 Jun 2015

  • Link

    Direct link to this answer

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#answer_183895

  • Link

    Direct link to this answer

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#answer_183895

Open in MATLAB Online

Try this:

% Some data:

x = rand(30,1);

y = rand(30,1);

z = rand(30,1);

% Each data point is in one of 5 groups:

group = randi(5,30,1);

% What are those unique groups?

uniqueGroups = unique(group);

% RGB values of your favorite colors:

colors = brewermap(length(uniqueGroups),'Set1');

% Initialize some axes

view(3)

grid on

hold on

% Plot each group individually:

for k = 1:length(uniqueGroups)

% Get indices of this particular unique group:

ind = group==uniqueGroups(k);

% Plot only this group:

plot3(x(ind),y(ind),z(ind),'.','color',colors(k,:),'markersize',20);

end

legend('group 1','group 2','group 3','group 4','group 5')

Grouping Data for a 3d Scatter Plot (3)

The brewermap function is available on the File Exchange.

3 Comments

Show 1 older commentHide 1 older comment

Walter Roberson on 24 Jun 2015

Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_294334

  • Link

    Direct link to this comment

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_294334

Open in MATLAB Online

It can be done without the loop.

x = rand(30,1);

y = rand(30,1);

z = rand(30,1);

group = randi(5,30,1);

[uniqueGroups, uga, ugc] = unique(group);

colors = brewermap(length(uniqueGroups),'Set1'); %or any other way of creating the colormap

markersize = 20; %change to suit taste

scatter3(x(:), y(:), z(:), markersize, colors(ugc,:));

And in the case where the groups are known to be small positive integers (as was the case in your example)

x = rand(30,1);

y = rand(30,1);

z = rand(30,1);

group = randi(5,30,1);

colors = brewermap(max(group),'Set1'); %or any other way of creating the colormap

markersize = 20; %change to suit taste

scatter3(x(:), y(:), z(:), markersize, colors(group,:));

Basically once you already have the data, the only complication is creating the color table with the desirable set of colors for each group. Once that is done, a single call creates the plot and colors each marker appropriately.

When it is required that everything be done through the interface, the single largest problem, at least in R2014a, is that scatter3() is not a plot that can be chosen from the interface once you have your columns selected. If it were available then after that the interface could be used to get into the scatter plot and edit the CData values to suit -- a process made much easier if you have the color table already stored.

Alamgir M S M on 9 Mar 2019

Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_679116

  • Link

    Direct link to this comment

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_679116

Edited: Walter Roberson on 9 Mar 2019

Open in MATLAB Online

Hi, that group is little different for me.

This is my Data-

[705.7142857 705.7142857 173.4285714 84.71428571 232.5714286 232.5714286 114.2857143 55.14285714 25.57142857 74.85714286 35.42857143 15.71428571 5.857142857 5.857142857]

I want to group same data into 1 group. This is 14*1 matrix where it has 3 pairs(705.7142857 705.7142857, 232.5714286 232.5714286 & 5.857142857 5.857142857) of same value data. So, I want these 3 pairs into 3 groups and rest of them into other 8 groups.

Could you help me to change this line from your code:

group = randi(11,14,1);

Thank you.

Walter Roberson on 9 Mar 2019

Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_679260

  • Link

    Direct link to this comment

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_679260

Answered at https://www.mathworks.com/matlabcentral/answers/449110-hi-i-want-to-group-my-data-into-11-groups#answer_364549

Sign in to comment.

John Clarke on 24 Jun 2015

  • Direct link to this answer

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#answer_183897

  • Link

    Direct link to this answer

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#answer_183897

so there's no way to do it through the interface? I have to write code?

1 Comment

Show -1 older commentsHide -1 older comments

Walter Roberson on 24 Jun 2015

Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_294336

  • Link

    Direct link to this comment

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_294336

You need at least one line of code, just to start the scatter3 plot in the first place. Once the scatter3 plot exists you can do the rest through the interface.... but it is certainly less tedious if you also have a line of code to create the color table.

Sign in to comment.

Walter Roberson on 24 Jun 2015

  • Link

    Direct link to this answer

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#answer_183906

  • Link

    Direct link to this answer

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#answer_183906

It might depend upon which MATLAB version you are using, but at least up to R2014a, the graphical interface does not offer a method to start a scatter3 plot. It allows scatter plots to be started, but if you have a variable selected in the variable editor and have selected more than 2 columns, then the Plot tab greys out scatter3().

This might have been a limitation in R2014a; if you are using R2014b onwards perhaps it is possible.

If it was a 2D scatter plot you had been wanting to do, then it would have been possible using only the interface. Getting the colors right would be a nuisance using only the interface, but it would be possible.

Matters become much simpler if you were willing to type in at least one command.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

John Clarke on 24 Jun 2015

  • Link

    Direct link to this answer

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#answer_183915

  • Link

    Direct link to this answer

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#answer_183915

OK well thanks for the help all maybe I'll tackle the code writing after a good nights sleep when I'm in a better frame of mind.

2 Comments

Show NoneHide None

Walter Roberson on 24 Jun 2015

Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_294352

  • Link

    Direct link to this comment

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_294352

Open in MATLAB Online

The one line of code that is really needed is the one to create the scatter plot in the first case,

scatter3(x(:), y(:), z(:))

after that everything else can be done through the interface. But if you are going to type in the one command you can make things faster with

scatter3(x(:), y(:), z(:), 20, group(:))

provided that group contains small positive integers (max 128 on MS Windows before R2014b). After that it is just a matter of editing the colormap, which can be done through the interface. Most of us would rather write a small number of additional lines to set the colormap. For example,

scatter3(x(:), y(:), z(:), 20, group(:)); colormap(jet(5));

would do the whole coloring using 5 colors from the "jet" palette.

Christina Rigsby on 8 May 2022

Direct link to this comment

https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_2147165

  • Link

    Direct link to this comment

    https://nl.mathworks.com/matlabcentral/answers/225193-grouping-data-for-a-3d-scatter-plot#comment_2147165

How do you add a legend labeling the 5 groups you've visualized with the suggested code:

scatter3(x(:), y(:), z(:), 20, group(:)); colormap(jet(5));

?

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphicsFormatting and AnnotationColormaps

Find more on Colormaps in Help Center and File Exchange

Tags

  • scatterplot

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.


Grouping Data for a 3d Scatter Plot (13)

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

Contact your local office

Grouping Data for a 3d Scatter Plot (2024)

FAQs

Can you make a scatter plot with grouped data? ›

To create a scatterplot with groups in Minitab: Open the data file in Minitab. From the tool bar, select Graph > Scatterplot > One Y Variable > Groups Overlaid.

How to make a 3D scatter plot? ›

Create Chart

Choose the 'Type' of trace, then choose '3D Scatter' under '3D' chart type. Next, select 'X', 'Y' and 'Z' values from the dropdown menus. This will create a 3D scatter trace, as seen below.

How do you describe a 3D scatter plot? ›

3D scatter plots are used to plot data points on three axes in the attempt to show the relationship between three variables. Each row in the data table is represented by a marker whose position depends on its values in the columns set on the X, Y, and Z axes.

Can you make a scatter plot with categorical data? ›

A categorical scatter plot is a grid of different-sized circles. Each circle represents the intersection of two categories. In this type of chart, two categorical variables are usually placed along X- and Y- axes.

How do you organize data in a scatter plot? ›

Step 1: Organize your data

Since scatter graphs are meant to show how two numeric values are related to each other, they should both be displayed in two separate columns. The first column will usually be plotted on the X-axis and the second column on the Y-axis.

Can you do a 3D scatter plot in Excel? ›

The 3D scatter plot chart in Excel is mainly used to show the relationship between two sets of data related to each other. The scattered chart has X and Y variables. This chart helps show related data like rainfall vs. umbrellas sold, rainfall vs.

What is the X Y Z scatter plot? ›

Unlike a classic XY scatter chart, a 3D scatter plot displays data points on three axes (x, y, and z) in order to show the relationship between three variables. Therefore, it is often called an XYZ plot.

How to plot 3D data in Excel? ›

Go to the "Insert" tab in the Excel ribbon and select the desired chart type under the "Charts" section. Choose the 3D plot option that best fits your needs. Customize your chart by adding titles and labels and adjusting the appearance of the plot. Analyze your chart to identify trends and patterns in your data.

What is the size of the marker in a 3D scatter plot? ›

scatter3d(x,y,z) creates a scatter plot with markers at the locations specified by x , y , and z . The default type of the marker is a circle, the default color is "blue" and the default marker size is 36. This means the circle surrounding the marker has an area of 36 points squared.

Which Plotly method is used to create a 3D scatter plot? ›

scatter_3d. In a 3D scatter plot, each row of data_frame is represented by a symbol mark in 3D space. data_frame (DataFrame or array-like or dict) – This argument needs to be passed for column names (and not keyword names) to be used.

What is grouping in a scatter plot? ›

Groups are pairs of X-Y variables

Specify the pairs of variables to appear on your graph. In Y variables, enter multiple columns that you want to explain or predict. In X variables, for each Y variable, enter the corresponding numeric column that might explain or predict changes in the Y variable.

Can we use clustering for categorical data? ›

K-modes is a clustering algorithm used in data mining and machine learning to group categorical data into distinct clusters. Unlike K-means, which works with numerical data, K-modes focuses on finding clusters based on categorical attributes.

Is a scatter plot categorical or quantitative? ›

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.

What graph to use for grouped data? ›

a Bar Graph. Bar graphs are used to compare things between different groups or to track changes over time.

How do you make a scatter plot with multiple data sets? ›

To create a scatter plot with multiple data series in Excel, arrange your data in columns with x-values and y-values for each series. Select the data, then go to the "Insert" tab and choose the scatter plot type.

What type of data do you need to make a scatter plot? ›

The scatter diagram graphs pairs of numerical data, with one variable on each axis, to look for a relationship between them. If the variables are correlated, the points will fall along a line or curve. The better the correlation, the tighter the points will hug the line.

Can you do a scatter plot with multiple variables? ›

In Excel, creating a scatter plot with multiple data series can be done several ways. The easiest is to have a single column in your data containing the X values for all of your data series, and then have a separate column for the Y values of each individual data series.

References

Top Articles
Latest Posts
Article information

Author: Tish Haag

Last Updated:

Views: 5885

Rating: 4.7 / 5 (47 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.