Azzera filtri
Azzera filtri

Drawing a coloured line into a 2D coordinate System

3 visualizzazioni (ultimi 30 giorni)
Hello people,
I want to draw a 2D coordinatesystem containing a coloured line were the colour is defined by a value. I'll try to explain it in a mathematic way here:
We have a 2D Matrix M containing real numbers. The graph f is then defined as follows:
f(x,y) = C(M[x][y]) , where C(M[x][y]) returns a colour depending on M[x][y]
The smaller M[x][y], the greener the color and the larger M[x][y], the redder the number.
I already found imagesc but it seems that it does not fit my purpose.
Thanks in advance!

Risposta accettata

Cam Salzberger
Cam Salzberger il 3 Ago 2018
To clarify this in plain terms, would you like to see a line that changes color as it changes position? Like this, for example? There is no way in MATLAB to have a single line object have different colors along it, but there are several workarounds. Here's one example, using a surface object instead of a line. You could also just do a lot of short line segments with small color changes.
Or are you asking for a "colored square", where the full 2-D plot is filled in, and the color is based on position? For example, this. In that case, surf using interpolated colors and edges off works pretty well when viewed from the top - view(2).
Hope that helps!
-Cam
  3 Commenti
Rodi Ak
Rodi Ak il 5 Ago 2018
I could solve the Problem by defining a colormap with a wider range of color.
Cam Salzberger
Cam Salzberger il 15 Ago 2018
It really depends on what you want to see on the map. Are you mostly concerned with points that are above and below certain amounts? If that's the case, the limiting using caxis seems like the right approach, you just may broaden the range a bit.
The colormap tends to be used to be able to tell at a glance where in the numerical range an area falls. This is easy when the colormap ranges across primarily just two colors. Like in your example, the more blue it is, the lower, and the more yellow it is, the higher it is. If you are more concerned with determining areas of similar color, then you may be interested in a colormap with more colors, like 'hsv'. See the map input argument here. You can also create your own colormap, if that's insufficient.
If instead you are seeing small changes at low values that you want distinguished, but also large changes at high values, you may consider using the log of the data for the color argument, rather than its linear values. This would be similar to using semilogy for a 2-D plot, except you'd take the logarithm explicitly. If you want accurate labels on your colorbar for the real values, you may need to set them yourself.
Hope that helps!
-Cam

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by