YouTip LogoYouTip

Matplotlib Marker

In the plotting process, if we want to define some custom markers for the coordinates, we can use the `marker` parameter of the **`plot()`** method. The following example defines a solid circle marker: ## Example ```python import matplotlib.pyplot as plt import numpy as np ypoints = np.array([1,3,4,5,8,9,6,1,3,4,5,2,4]) plt.plot(ypoints, marker ='o') plt.show() The result is shown below: !(#) The symbols that can be defined for `marker` are as follows: | Marker | Symbol | Description | | --- | --- | --- | | "." | ![Image 2: m00](#) | Point | | "," | ![Image 3: m01](#) | Pixel | | "o" | ![Image 4: m02](#) | Circle | | "v" | ![Image 5: m03](#) | Triangle Down | | "^" | ![Image 6: m04](#) | Triangle Up | | "" | ![Image 8: m06](#) | Triangle Right | | "1" | ![Image 9: m07](#) | Tri Down | | "2" | ![Image 10: m08](#) | Tri Up | | "3" | ![Image 11: m09](#) | Tri Left | | "4" | ![Image 12: m10](#) | Tri Right | | "8" | ![Image 13: m11](#) | Octagon | | "s" | ![Image 14: m12](#) | Square | | "p" | ![Image 15: m13](#) | Pentagon | | "P" | ![Image 16: m23](#) | Plus (filled) | | "*" | ![Image 17: m14](#) | Star | | "h" | ![Image 18: m15](#) | Hexagon 1 | | "H" | ![Image 19: m16](#) | Hexagon 2 | | "+" | ![Image 20: m17](#) | Plus | | "x" | ![Image 21: m18](#) | X | | "X" | ![Image 22: m24](#) | X (filled) | | "D" | ![Image 23: m19](#) | Diamond | | "d" | ![Image 24: m20](#) | Thin Diamond | | "|" | ![Image 25: m21](#) | Vline | | "_" | ![Image 26: m22](#) | Hline | | 0 (TICKLEFT) | ![Image 27: m25](#) | Tick Left | | 1 (TICKRIGHT) | ![Image 28: m26](#) | Tick Right | | 2 (TICKUP) | ![Image 29: m27](#) | Tick Up | | 3 (TICKDOWN) | ![Image 30: m28](#) | Tick Down | | 4 (CARETLEFT) | ![Image 31: m29](#) | Caret Left | | 5 (CARETRIGHT) | ![Image 32: m30](#) | Caret Right | | 6 (CARETUP) | ![Image 33: m31](#) | Caret Up | | 7 (CARETDOWN) | ![Image 34: m32](#) | Caret Down | | 8 (CARETLEFTBASE) | ![Image 35: m33](#) | Caret Left (centered at base) | | 9 (CARETRIGHTBASE) | ![Image 36: m34](#) | Caret Right (centered at base) | | 10 (CARETUPBASE) | ![Image 37: m35](#) | Caret Up (centered at base) | | 11 (CARETDOWNBASE) | ![Image 38: m36](#) | Caret Down (centered at base) | | "None", " " or "" | | No marker | | '$...$' | ![Image 39: m37](#) | Render the specified text. For example, "$f$" uses the letter 'f' as the marker. | The following example defines the * marker: ## Example ```python import matplotlib.pyplot as plt import numpy as np ypoints = np.array([1,3,4,5,8,9,6,1,3,4,5,2,4]) plt.plot(ypoints, marker ='*') plt.show() The result is shown below: !(#) The following example defines the down caret marker: ## Example ```python import matplotlib.pyplot as plt import matplotlib.markers plt.plot([1,2,3], marker=matplotlib.markers.CARETDOWNBASE) plt.show() The result is shown below: !(#) ### fmt Parameter The `fmt` parameter defines the basic format, such as marker, line style, and color. `fmt = ''` For example, `o:r`, where `o` represents a solid circle marker, `:` represents a dashed line, and `r` represents the color red. ## Example ```python import matplotlib.pyplot as plt import numpy as np ypoints = np.array([6,2,13,10]) plt.plot(ypoints,'o:r') plt.show() The result is shown below: !(#) Line Styles: | Line Style Marker | Description | | --- | --- | | '-' | Solid line | | ':' | Dotted line | | '--' | Dashed line | | '-.' | Dash-dot line | Color Types: | Color Marker | Description | | --- | --- | | 'r' | Red | | 'g' | Green | | 'b' | Blue | | 'c' | Cyan | | 'm' | Magenta | | 'y' | Yellow | | 'k' | Black | | 'w' | White | ### Marker Size and Color We can customize the size and color of the markers using the following parameters: * `markersize`, abbreviated as **`ms`**: Defines the size of the marker. * `markerfacecolor`, abbreviated as **`mfc`**: Defines the color inside the marker. * `markeredgecolor`, abbreviated as **`mec`**: Defines the color of the marker's edge. Setting the marker size: ## Example ```python import matplotlib.pyplot as plt import numpy as np ypoints = np.array([6,2,13,10]) plt.plot(ypoints, marker ='o', ms =20) plt.show() The result is shown below: !(#) Setting the marker edge color: ## Example ```python import matplotlib.pyplot as plt import numpy as np ypoints = np.array([6,2,13,10]) plt.plot(ypoints, marker ='o', ms =20, mec ='r') plt.show() The result is shown below: !(#) Setting the marker face color: ## Example ```python import matplotlib.pyplot as plt import numpy as np ypoints = np.array([6,2,13,10]) plt.plot(ypoints, marker ='o', ms =20, mfc ='r') plt.show() The result is shown below: !(#) Customizing both the marker face and edge colors: ## Example ```python import matplotlib.pyplot as plt import numpy as np ypoints = np.array([6,2,13,10]) plt.plot(ypoints, marker ='o', ms =20, mec ='#4CAF50', mfc ='#4CAF50') plt.show() The result is shown below: !(#)
← Matplotlib LabelCharacter Isletter β†’