How can I "connect" the colorbar to my values of a scatter plot? (2024)

46 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Sim am 22 Jun. 2024 um 20:31

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot

Kommentiert: Star Strider vor etwa 20 Stunden

Akzeptierte Antwort: Star Strider

In MATLAB Online öffnen

How can I "connect" the colorbar to my values (between 0 and 1) of a scatter plot?

a = rand(1000,1);

C = 1-[a a a];

scatter(1:length(a),a,60,C,'fill')

colormap(C);

colorbar;

How can I "connect" the colorbar to my values of a scatter plot? (2)

Here you can see that the colorbar is not gradually changing from 0 to 1.. How to fix it?

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Star Strider am 22 Jun. 2024 um 20:58

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#answer_1475801

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#answer_1475801

In MATLAB Online öffnen

I am not certain what you want to do, or what you intend by ‘connect’.

One option —

a = rand(1000,1);

% C = 1-[a a a];

C = ([1;1;1]*linspace(1, 0, 1000)).';

scatter(1:length(a),a,60,C,'fill')

colorbar;

How can I "connect" the colorbar to my values of a scatter plot? (4)

.

6 Kommentare

4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden

Sim am 22 Jun. 2024 um 21:04

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3193501

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3193501

Bearbeitet: Sim am 22 Jun. 2024 um 21:16

In MATLAB Online öffnen

Thanks a lot for youer answer @Star Strider!

With "connect", I mean that, given a certain colormap with a certain number of colors (which change gradually from each other), the values of my scatter plot (i.e. "a = rand(1000,1)", which are between 0 and 1), should get the proper colors from that defined colormap...

About your option, more or less yes, something like that... however, in your colorbar the 1 corresponds to black and 0 corresponds to white, but the scatterplot shows that 1000 corresponds to black... I mean, the variation of color from white to black should go from zero to one, in the y-axis direction, and not in the x-axis direction, right?.....

I was thinking about a solution similar to yours... but I am not sure if it is correct......

a = rand(1000,1);

C = 1-[a a a];

scatter(1:length(a),a,60,C,'fill')

l = 1-linspace(0,1,1000)';

colormap([l l l])

colorbar

How can I "connect" the colorbar to my values of a scatter plot? (6)

Star Strider am 22 Jun. 2024 um 21:36

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3193521

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3193521

In MATLAB Online öffnen

As always, my pleasure!

It would appear to be, if that is the result you want.

You can avoid the interruptions in the axes near the lower end of your plot by by bringing them to the top layer —

a = rand(1000,1);

C = ([1;1;1]*linspace(1, 0, 1000)).';

scatter(a,1:length(a),60,C,'fill')

colormap(C);

colorbar;

Ax = gca;

Ax.Layer = 'top';

How can I "connect" the colorbar to my values of a scatter plot? (8)

That is the only other change I would make to your code if it now does what you want it to do.

.

Sim vor etwa 24 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3194191

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3194191

Bearbeitet: Sim vor etwa 23 Stunden

In MATLAB Online öffnen

Hi @Star Strider, I am very sorry, I think I did a mistake to explain my needs, my fault.... :-(

In your figure, the change of color, from white (corresponding to 0) to black (corresponding to 1), goes from value 0 to value 1000. Instead, what I would need is that the change of color, from white (corresponding to 0) to black (corresponding to 1), goes from value 0 to value 1, since my values in

a = rand(1000,1);

range from 0 to 1, and not from 0 to 1000.

In other words, what I would need is something like this (which I think it is not very correct since I use directly the values of "a" as inputs for the color of the scatter plot! Obviouslly, your opinion and the opinion of other users of this Matlab community is very welcome!):

a = rand(1000,1);

C = 1-[a a a];

scatter(1:length(a),a,60,C,'fill')

l = 1-linspace(0,1,1000)';

colormap([l l l])

colorbar

How can I "connect" the colorbar to my values of a scatter plot? (10)

Here, we assign a color of the colorbar - which goes from white, at 0, to black, at 1 -, to each value of

a = rand(1000,1);

which values range from 0 to 1.

For example, if we consider the minimum value of "a":

a(285)

ans =

0.0013207800733116

the corresponding point of the scatter plot should have, basically, a white color, since white corresponds to the value 0 in the colorbar.

As another example,

a(3)

ans =

0.88899234515285

and the corresponding point of the scatter plot, should have a very dark grey, almost black, since black corresponds to the value 1 in the colorbar.

Star Strider vor etwa 21 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3194361

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3194361

In MATLAB Online öffnen

I cannot understand what you want to change.

The colour assignmentts appear to be correct.

I added a few lines to plot specific points with red and green circles, along with ttheir values.

ay = rand(1000,1);

ax = 1:length(ay);

C = 1-[ay ay ay];

scatter(ax,ay,60,C,'fill')

l = linspace(1,0,1000)';

colormap([l l l])

colorbar

format shortG

Point_1 = [ax(1) ay(1)]

Point_1 = 1x2

1 0.32606

<mw-icon class=""></mw-icon>

<mw-icon class=""></mw-icon>

Point_1000 = [ax(1000) ay(1000)]

Point_1000 = 1x2

1.0e+00 * 1000 0.94193

<mw-icon class=""></mw-icon>

<mw-icon class=""></mw-icon>

hold on

plot(Point_1(1), Point_1(2), 'or', 'MarkerSize',11)

plot(Point_1000(1), Point_1000(2), 'og', 'MarkerSize',11)

hold off

How can I "connect" the colorbar to my values of a scatter plot? (12)

I will do my best to help you. I need to understand what you want to do.

.

Sim vor etwa 20 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3194381

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3194381

Bearbeitet: Sim vor etwa 20 Stunden

In MATLAB Online öffnen

That's great, thanks a lot! Problem solved!

I was not sure about this code:

a = rand(1000,1);

C = 1-[a a a];

scatter(1:length(a),a,60,C,'fill')

l = linspace(1,0,1000)';

colormap([l l l])

colorbar

but your further check - with the two red and green points -, confirmed what I was thinking/expecting :-)

Thanks a lot for your great support!

And, I am really sorry for my confusion... My fault :-)

Star Strider vor etwa 20 Stunden

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3194421

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2131106-how-can-i-connect-the-colorbar-to-my-values-of-a-scatter-plot#comment_3194421

As always, my pleasure!

No worries! Often, these sorts of mathematical concepts are difficult to describe.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABGraphicsFormatting and AnnotationColormapsBlue

Mehr zu Blue finden Sie in Help Center und File Exchange

Tags

  • colorbar
  • colormap
  • scatter

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by How can I "connect" the colorbar to my values of a scatter plot? (15)

How can I "connect" the colorbar to my values of a scatter plot? (16)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

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

Europa

  • 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)

Asien-Pazifik

Kontakt zu Ihrer lokalen Niederlassung

How can I "connect" the colorbar to my values of a scatter plot? (2024)

FAQs

How to give color to a scatter plot? ›

The scatter plot's markers will all have the same colour if the c parameter is passed a single-colour string or a tuple of RGBA values. For instance, a scatter plot with blue markers would be produced if c='blue' or c=(0.0, 0.0, 1.0, 1.0).

How to get colorbar in Matplotlib? ›

In Matplotlib they are drawn into a dedicated Axes . Colorbars are typically created through Figure. colorbar or its pyplot wrapper pyplot. colorbar , which internally use Colorbar together with make_axes_gridspec (for GridSpec -positioned Axes) or make_axes (for non- GridSpec -positioned Axes).

How do you plot a connected scatter plot in Python? ›

Connected scatterplots are just a mix between scatterplots and linecharts. It can be made using the plot() function of matplotlib with the possible parameters: x : The horizontal coordinates of the data points. y : The vertical coordinates of the data points.

How to specify colors to scatter plots in Python? ›

Matplotlib Customize Plot Colors Using Scatter Plots

scatter() function is used to create each scatter plot, specifying the x and y coordinates along with the color ('c') of the markers.

How do you add color to a plot? ›

To change the color of a plot, simply add a color parameter to the plot function and specify the value of the color.

What is the best color for a scatter plot? ›

Unless you have a very good reason to add color, it is probably best to keep a scatter plot grayscale.

What is colorbar in plot? ›

Colorbars are a visualization of the mapping from scalar values to colors. In Matplotlib they are drawn into a dedicated axis. Note: Colorbars are typically created through Figure.

How to put colorbar in subplot? ›

To draw a colorbar or legend alongside particular row(s) or column(s) of the subplot grid, use the row , rows , col , or cols keyword arguments.

How do you add a Colorbar to a contour plot in Python? ›

A color bar can be added to the filled contour plot using either the pyplot. colorbar() function or the figure. colorbar() method. – There is no axes method for a color bar.

How to connect scatter points in Matplotlib? ›

Add lines to the scatterplot: To add lines to the scatterplot, we can use the NumPy library's np. sort() function to sort the x and y arrays in ascending order. Once the data is sorted, we can then use Matplotlib's plt. plot() function to plot a line connecting each pair of sorted points.

Do you connect scatter plots? ›

Connected scatterplot makes sense in specific conditions where both the scatterplot and the line chart are not enough: When doing a line chart, it is sometimes difficult to visualize where the breaks in the curve are, and thus when the observation have been done.

How do you specify colors in a scatter plot? ›

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" .

What is a scatter plot in Matplotlib? ›

A scatter plot is a diagram where each value in the data set is represented by a dot. The Matplotlib module has a method for drawing scatter plots, it needs two arrays of the same length, one for the values of the x-axis, and one for the values of the y-axis: x = [5,7,8,7,2,17,2,9,4,11,12,9,6]

How do you add color to a box plot? ›

The easiest way is to give a vector ( myColor here) of colors when you call the boxplot() function. Use ifelse statements to add the color you want to a specific name.

How do you apply a color to a chart? ›

Change the color of a chart

Tip: Chart styles (combinations of formatting options and chart layouts) use the theme colors. To change color schemes, switch to a different theme. In Excel, click Page Layout, click the Colors button, and then pick the color scheme you want or create your own theme colors.

How do I change color of the dots in scatter plot R? ›

Now to change the colors of a scatterplot using plot(), simply select the column on basis of which different colors should be assigned to various points. Pass the column that will help differentiate between points to “col” attribute. Example: R.

Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated:

Views: 5825

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.