scatter3 -- plotting points with different colors attributes (2024)

5 views (last 30 days)

Show older comments

Roger Breton on 22 Dec 2021

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes

Commented: Matt J on 23 Dec 2021

I would like to explore a different approach with my scatter3 plotting project.

So far, I'm using a custom data tip to identify numerically colors (3D points) that are outside the gamut of my output device :

scatter3 -- plotting points with different colors attributes (2)

As you can see, there are points that clearly lie outside the 3D volume of the 'destination gamut'. For example, the data point shown above is 10.3511. Now, I'd to explore the possibility of adding a 'white outline' to those points, to further drive home the idea that they are out of gamut, for my students. What would be my best approach?

I was thinking, perhaps, to construct a loop to sub-select all the point that have less than, say, 1 DeltaE, and store them in a 'inGamut' array. And sending the rest in an 'outGamut' array, and use two calls to scatter3; one call for the inGamut points, followed by a second call, where I would specify additional attribute such as "outline" (or stroke -- don't know how it's called in Matlab) for the outGamut points.

It's either than or go through all the points in a loop and have them plotted differently depending on their DeltaE value.

Which would be a good (easiest) approach?

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (1)

Matt J on 22 Dec 2021

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#answer_860510

Edited: Matt J on 23 Dec 2021

Open in MATLAB Online

The first option sounds the closest to what I would do, except that I see no reason to use a loop. Just use logical indexing:

in=DE76<1; out=~in;

inGammut={X(in), Y(in), Z(in)};

outGammut={X(out), Y(out), Z(out)};

hold on

scatter3(inGammut{:},80,RGB,'filled');

scatter3(outGammut{:},_____);

hold off

5 Comments

Show 3 older commentsHide 3 older comments

Roger Breton on 23 Dec 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#comment_1900875

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#comment_1900875

Thank you Matt,

I experimented with a loop and, boy!, did that take forever :-) I had to interrupt execution...

Is the first line above some kind of pseudocode? I never seen this notation.

I confess my ignorance in Matlab... So far, I managed to get this far :

DE76reshape = reshape(DE76, [12, 1])

myTable = table(Lab(1,:)', Lab(2,:)',Lab(3,:)', DE76reshape)

inGamutTable = myTable(myTable.DE76reshape < 1,:)

First, as you can see, the DE76 was a 4 x 3 array. So I converted it to a column vector. Then I created a table made up of the three column vectors from my Lab array (which I transposed with the apostrophe operator) plus the DE76 column vector. At that point, I extracted the colors meeting my criteria using the third statement above.

The table has only value in finding colors that have than 1 DeltaE value. But once I get that table, then I need to turn it back into compatible arguments for the scatter3 function... Which I'm having difficulty with...

Matt J on 23 Dec 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#comment_1900955

Edited: Matt J on 23 Dec 2021

Open in MATLAB Online

You don't need the table at all. The only pseudocode in what I had above is the 2nd call to scatter3(). You need to fill in the blank with whatever arguments you want to use for the outGammut points.

[X,Y,Z]=deal(Lab(1,:), Lab(2,:),Lab(3,:));

in=(DE76(:)<1); out=~in;

inGammut={X(in), Y(in), Z(in)};

outGammut={X(out), Y(out), Z(out)};

hold on

scatter3(inGammut{:},80,RGB,'filled');

scatter3(outGammut{:},_____);

hold off

Roger Breton on 23 Dec 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#comment_1901680

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#comment_1901680

Thank you, Matt, for your new reply :-)

Please allow me to follow at my own pace (I'm not a rocket scientist...)

I found the "deal" function in Matlab's Help but I'm not sure what it does. I guess you are taking my initial Lab values as input and transforming them in some way? Many Matlab's functions are not for the faint of heart...

When you issue in=(DeltaE(:)<1), I don't follow? Doesn't DeltaE need two arguments? I confess I'm not familiar with the super compact notation but your statement doesn't seem to have any arguments at all?

Roger Breton on 23 Dec 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#comment_1901755

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#comment_1901755

Open in MATLAB Online

By the way...

I tried running your code in a new script.

I wasn't expecting the deal function would break down the Lab [3 x n] variable (row1=L, row2=a, row3=b) into separate row vectors -- neat!

But the compiler complains that it does not recognize the 'deltaE' function :

Unrecognized function or variable 'deltaE'.

I suspect it needs a second argument, somehow...

Matt J on 23 Dec 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#comment_1901760

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/1616275-scatter3-plotting-points-with-different-colors-attributes#comment_1901760

Where I had DeltaE, I really meant DE76.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABLanguage FundamentalsLoops and Conditional Statements

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

  • scatter3
  • deltae
  • loop

Products

  • Image Processing Toolbox

Release

R2021b

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.


scatter3 -- plotting points with different colors attributes (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

scatter3 -- plotting points with different colors attributes (2024)

FAQs

Which function was used to plot apply different Colours to scatter points? ›

With Pyplot, you can use the scatter() function to draw a scatter plot.

How do you plot a graph in different colors in Matlab? ›

thisIndex = ceil(row/5); thisColor = plotColors(thisIndex, :); plot(thisX, thisY, '-', 'Color', thisColor, 'LineWidth', 2); hold on; % Leave plots up so we'll see all of them at the end.

How to change scatter plot color in Matlab? ›

scatter( x , y , sz , c ) specifies the circle colors. You can specify one color for all the circles, or you can vary the color. For example, you can plot all red circles by specifying c as "red" . scatter(___, "filled" ) fills in the circles.

How to give different colors in a scatter plot? ›

We import Matplotlib and NumPy, two required libraries. Then, we use the NumPy rand function to produce some random x and y data and a list of random colours for each point in the scatter plot. The scatter function is then used to construct a scatter plot with various colours using the x, y, and c parameters.

How to specify line style and colours in a graph in MATLAB? ›

You can use the linespec argument to specify a named color, but to specify a custom color, set an object property. For example, Line objects have a Color property. Create a plot with a purple line that has circular markers. Specify only the line and marker symbols in the linespec argument.

What is the difference between plot and scatter in MATLAB? ›

Yes, plot connects points in the order in which they appear in the input sequence; scatter does not connect, and has additional capabilities for varying the symbol, size, and color.

What is the X Y Z scatter plot? ›

An XYZ class scatter plot is a scatter plot with symbols that mark the intersection of X, Y, and Z column data based on a required fourth value (Class column). Class scatter plots group data into discrete classes (bins). The data points are displayed using the symbol assigned to the class.

How to draw 3-D plots in MATLAB? ›

To plot a 3D surface from a data file in MATLAB, you will need to have the data file open in MATLAB. Once you have the data file available, you can use the plot3 command to plot the data. The plot3 command will create a 3D plot of the data. You can also use the surf command to create a 3D surface plot.

What is the function to give color to plot? ›

Note that the rgb() function can be used to produce any color via red, green, blue proportions and return a hexadecimal representation.

What is the function of the scatter point? ›

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 the function of scatter plot in Excel? ›

Scatter charts are commonly used for displaying and comparing numeric values, such as scientific, statistical, and engineering data. These charts are useful to show the relationships among the numeric values in several data series, and they can plot two groups of numbers as one series of xy coordinates.

How to make different colors in R? ›

In R, colors can be specified either by name (e.g col = “red”) or as a hexadecimal RGB triplet (such as col = “#FFCC00”). You can also use other color systems such as ones taken from the RColorBrewer package.

References

Top Articles
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated:

Views: 6188

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.