Hauptinhalt

Die Übersetzung dieser Seite ist veraltet. Klicken Sie hier, um die neueste Version auf Englisch zu sehen.

colormap

Anzeigen und Festlegen der aktuellen Farbtabelle

Beschreibung

Festlegen einer Farbtabelle

colormap map setzt die Farbtabelle für die aktuelle Abbildung auf die angegebene vordefinierte Farbtabelle. colormap hot setzt beispielsweise die Farbtabelle auf hot.

Wenn Sie die Farbtabelle für die Abbildung festlegen, verwenden die Achsen und Diagramme dieser Abbildung dieselbe Farbtabelle. Die neue Farbtabelle hat dieselbe Länge (Anzahl Farben) wie die aktuelle Farbtabelle. Wenn Sie diese Syntax verwenden, können Sie keine benutzerdefinierte Länge für die Farbtabelle festlegen. Weitere Informationen über Farbtabellen finden Sie im Abschnitt Mehr über.

Beispiel

colormap(map) setzt die Farbtabelle für die aktuelle Abbildung auf die von map angegebene Farbtabelle.

Beispiel

colormap(target,map) legt die Farbtabelle für die Abbildung, Achsen oder eigenständige Visualisierung fest, die von target angegeben werden, statt für die aktuelle Abbildung.

Beispiel

cmap = colormap(___) legt die Farbtabelle fest und gibt sie als dreispaltige Matrix aus RGB-Tripeln zurück. Legen Sie cmap als Ausgabeargument fest; verwenden Sie eine der vorherigen Syntaxen mit runden Klammern.

Abrufen der aktuellen Farbtabelle

cmap = colormap gibt die Farbtabelle für die aktuelle Abbildung als dreispaltige Matrix aus RGB-Tripeln zurück.

Beispiel

cmap = colormap(target) gibt die Farbtabelle für die von target angegebene(n) Abbildung, Achsen oder eigenständige Visualisierung zurück.

Beispiel

Beispiele

alle reduzieren

Erstellen Sie ein Oberflächendiagramm und legen Sie als Farbtabelle winter fest.

surf(peaks)
colormap winter

Figure contains an axes object. The axes object contains an object of type surface.

Ändern Sie zunächst die Farbtabelle für die aktuelle Abbildung auf summer.

surf(peaks)
colormap summer

Figure contains an axes object. The axes object contains an object of type surface.

Setzen Sie nun die Farbtabelle wieder auf den Standardwert Ihres Systems. Wenn Sie die Standardeinstellung nicht geändert haben, ist die Standard-Farbtabelle parula.

colormap default

Figure contains an axes object. The axes object contains an object of type surface.

Mithilfe der Funktionen tiledlayout und nexttile können Sie Diagramme gekachelt anzeigen. Rufen Sie die Funktion tiledlayout auf, um ein kachelartiges 2x1-Diagrammlayout zu erstellen. Rufen Sie die nexttile-Funktion auf, um die Achsenobjekte ax1 und ax2 zu erstellen. Übergeben Sie das Achsenobjekt an die colormap-Funktion, um eine andere Farbtabelle für jede Achse festzulegen. Erstellen Sie bei den oberen Achsen ein Oberflächendiagramm mithilfe der Farbtabelle spring. Erstellen Sie bei den unteren Achsen ein Oberflächendiagramm mithilfe der Farbtabelle winter.

tiledlayout(2,1)
ax1 = nexttile;
surf(peaks)
colormap(ax1,spring)

ax2 = nexttile; 
surf(peaks)
colormap(ax2,winter)

Figure contains 2 axes objects. Axes object 1 contains an object of type surface. Axes object 2 contains an object of type surface.

Sie können die Anzahl Farben in einer Farbtabelle festlegen, indem Sie eine Ganzzahl als Eingabeargument für die eingebaute Farbtabelle verwenden. Verwenden Sie fünf Karten aus der Farbtabelle „parula“.

mesh(peaks)
colormap(parula(5))

Figure contains an axes object. The axes object contains an object of type surface.

Sie können eine benutzerdefinierte Farbtabelle erstellen, indem Sie eine dreispaltige Matrix mit Werten zwischen 0,0 und 1,0 definieren. Jede Zeile definiert ein RGB-Tripel mit drei Elementen. Die erste Spalte legt die Rot-Intensität fest. Die zweite Spalte legt die Grün-Intensität fest. Die dritte Spalte legt die Blau-Intensität fest.

Verwenden Sie eine Farbtabelle mit Blauwerten, indem Sie die ersten zwei Spalten auf null setzen.

map = [0 0 0.3
    0 0 0.4
    0 0 0.5
    0 0 0.6
    0 0 0.8
    0 0 1.0];

surf(peaks)
colormap(map)

Figure contains an axes object. The axes object contains an object of type surface.

Erstellen Sie ein Oberflächendiagramm der peaks-Funktion und legen Sie eine Farbtabelle fest.

mesh(peaks)
colormap(autumn(5))

Figure contains an axes object. The axes object contains an object of type surface.

Geben Sie die dreispaltige Wertematrix aus, die die im Diagramm verwendeten Farben definiert. Jede Zeile ist ein RGB-Tripel-Farbwert, der eine Farbe der Farbtabelle festlegt.

cmap = colormap
cmap = 5×3

    1.0000         0         0
    1.0000    0.2500         0
    1.0000    0.5000         0
    1.0000    0.7500         0
    1.0000    1.0000         0

Übergeben Sie das Achsenobjekt an die colormap-Funktion, um die Farbtabellenwerte bestimmter Achsen auszugeben.

Erstellen Sie eine gekachelte Ansicht zweier Diagramme, indem Sie die Funktionen tiledlayout und nexttile verwenden. Rufen Sie die Funktion tiledlayout auf, um ein kachelartiges 2x1-Diagrammlayout zu erstellen. Rufen Sie die nexttile-Funktion auf, um die Achsenobjekte ax1 und ax2 zu erstellen. Zeigen Sie daraufhin die zwei ausgefüllten Konturdiagramme mit verschiedenen Farbtabellen an.

tiledlayout(2,1)
ax1 = nexttile;
contourf(peaks)
colormap(ax1,hot(8))

ax2 = nexttile;
contourf(peaks)
colormap(ax2,pink)

Figure contains 2 axes objects. Axes object 1 contains an object of type contour. Axes object 2 contains an object of type contour.

Übergeben Sie ax1 an die colormap-Funktion, um die im oberen Diagramm verwendeten Farbtabellenwerte auszugeben. Jede Zeile ist ein RGB-Tripel-Farbwert, der eine Farbe der Farbtabelle festlegt.

cmap = colormap(ax1)
cmap = 8×3

    0.3333         0         0
    0.6667         0         0
    1.0000         0         0
    1.0000    0.3333         0
    1.0000    0.6667         0
    1.0000    1.0000         0
    1.0000    1.0000    0.5000
    1.0000    1.0000    1.0000

Laden Sie den Datensatz spine, der das Bild X und dessen zugehörige Farbtabelle map zurückgibt. Zeigen Sie X mithilfe der image-Funktion an und setzen Sie die Farbtabelle auf map.

load spine
image(X)
colormap(map)

Figure contains an axes object. The axes object contains an object of type image.

Eingabeargumente

alle reduzieren

Farbtabelle für das neue Farbschema, angegeben als Name der Farbtabelle, dreispaltige Matrix aus RGB-Tripeln oder 'default'. Ein Farbtabellen-Name legt eine vordefinierte Farbtabelle mit derselben Anzahl Farben wie die aktuelle Farbtabelle fest. Eine dreispaltige Matrix aus RGB-Tripeln legt eine benutzerdefinierte Farbtabelle fest. Sie können die Matrix selbst erstellen oder eine der vordefinierten Farbtabellen-Funktionen aufrufen, um die Matrix zu erstellen. colormap(parula(10)) setzt beispielsweise die Farbtabelle der aktuellen Abbildung auf eine Auswahl von 10 Farben aus der Farbtabelle parula.

Ein Wert von 'default' setzt die Farbtabelle auf die Standard-Farbtabelle für das Zielobjekt.

Name der Farbtabelle

Die vordefinierten Farbtabellen sind in der folgenden Tabelle aufgeführt.

Name der FarbtabelleFarbskala

parula

Colorbar showing the colors of the parula colormap. The colormap starts at dark blue and transitions to lighter blue, green, orange and yellow. The transitions between colors are more perceptually uniform than in most other colormaps.

turbo

Colorbar showing the colors of the turbo colormap. The colormap starts at dark blue and transitions to lighter blue, bright green, orange, yellow, and dark red. This colormap is similar to jet, but the transitions between colors are more perceptually uniform than in jet.

hsv

Colorbar showing the colors of the hsv colormap. The colormap starts at red and transitions to yellow, bright green, cyan, dark blue, magenta, and bright orange.

hot

Colorbar showing the colors of the hot colormap. The colormap starts at dark red and transitions to bright red, orange, yellow, and white.

cool

Colorbar showing the colors of the cool colormap. The colormap starts at cyan and transitions to light blue, light purple, and magenta.

spring

Colorbar showing the colors of the spring colormap. The colormap starts at magenta and transitions to pink, light orange, and yellow.

summer

Colorbar showing the colors of the summer colormap. The colormap starts at medium green and transitions to yellow.

autumn

Colorbar showing the colors of the autumn colormap. The colormap starts at bright orange and transitions to yellow.

winter

Colorbar showing the colors of the winter colormap. The colormap starts at dark blue and transitions to bright green.

gray

Colorbar showing the gray colormap. The colormap starts at black and transitions to white.

bone

Colorbar showing the bone colormap. This colormap has colors that are approximately gray with a slight blue color tint. The colormap starts at dark gray and transitions to white.

copper

Colorbar showing the copper colormap. This colormap starts at black and transitions to a medium orange, similar to the color of copper.

pink

Colorbar showing the pink colormap. This colormap starts at dark red and transitions to dark pink, tan, and white.

sky (seit R2023a)

Colorbar showing the sky colormap. This colormap starts at a very light shade of blue and transitions to a darker shade of blue.

abyss (seit R2023b)

Colorbar showing the abyss colormap. This colormap starts at a very dark shade of blue and transitions to a lighter shade of blue.

nebula (seit R2025a)

Colorbar showing the nebula colormap. This colormap starts at a medium shade of blue and transitions to a bright shade of red.

jet

Colorbar showing the colors of the jet colormap. The colormap starts at dark blue and transitions to light blue, bright green, orange, yellow, and dark red.

lines

Colorbar showing the colors of the lines colormap. The colormap contains a repeating pattern of colors: dark blue, dark orange, dark yellow, dark purple, medium green, light blue, and dark red.

colorcube

Colorbar showing the colors of the colorcube colormap. The colormap is a course sampling of the RGB colorspace.

prism

Colorbar showing the colors of the prism colormap. The colormap contains a repeating pattern of colors: red, orange, yellow, green, blue, and purple.

flag

Colorbar showing the colors of the flag colormap. The colormap contains a repeating pattern of colors: red, white, blue, and black.

white

Colorbar showing the white colormap, which is entirely white.

Dreispaltige Matrix

Um eine benutzerdefinierte Farbtabelle zu erstellen, legen Sie map als dreispaltige Matrix aus RGB-Tripeln fest, wobei jede Zeile eine Farbe festlegt. Ein RGB-Tripel ist ein aus drei Elementen bestehender Zeilenvektor, dessen Elemente die Intensitäten der Rot-, Grün- und Blaukomponenten der Farbe angeben. Die Intensitäten können double- oder single-Werte im Bereich [0;1] oder uint8-Werte im Bereich [0;255] sein. Diese Matrix legt beispielsweise eine Farbtabelle mit fünf Farben fest.

map = [0.2 0.1 0.5
    0.1 0.5 0.8
    0.2 0.7 0.6
    0.8 0.7 0.3
    0.9 1 0];

Diese Tabelle führt die RGB-Tripelwerte für häufige Farben auf.

Farbedouble- oder single-RGB-Tripeluint8-RGB-Tripel
gelb[1 1 0][255 255 0]
magenta[1 0 1][255 0 255]
cyan[0 1 1][0 255 255]
rot[1 0 0][255 0 0]
grün[0 1 0][0 255 0]
blau[0 0 1][0 0 255]
weiß[1 1 1][255 255 255]
schwarz[0 0 0][0 0 0]

Datentypen: char | double | single | uint8

Ziel, angegeben als einer dieser Werte:

  • Figure-Objekt. Die Abbildungs-Farbtabelle gilt für Diagramme auf allen Achsen in der Abbildung.

  • Axes-Objekt, PolarAxes-Objekt oder GeographicAxes-Objekt. Sie können für die verschiedenen Achsen einer Abbildung eine einzigartige Farbtabelle festlegen.

  • Eigenständige Visualisierung mit der Eigenschaft Colormap. Sie können beispielsweise die Farbtabelle eines HeatmapChart-Objekts ändern oder abfragen.

Ausgabeargumente

alle reduzieren

Farbtabellenwerte, zurückgegeben als dreispaltige Matrix aus RGB-Tripeln. Jede Zeile der Matrix definiert ein RGB-Tripel, das eine Farbe der Farbtabelle angibt. Die Werte liegen im Bereich [0;1].

Mehr über

alle reduzieren

Tipps

  • Verwenden Sie die clim-Funktion, um die Grenzwerte der Farbtabelle und die Beziehung zwischen den Grenzwerten und dem Bereich Ihrer Daten zu steuern.

    Vor R2022a: Verwenden Sie caxis; Syntax und Argumente sind zu clim identisch.

Versionsverlauf

Eingeführt vor R2006a

alle erweitern