Reputation: 326
This code is for KMeans Machine Learning:
from matplotlib import pyplot as plt
fig = plt.figure()
ax = fig.add_subplot()
centroid_colors=['bx','rx']
x = y = [1,2,3]
for color in centroid_colors:
ax.plot(x, y, color)
what is the meaning of bx, rx here, I can see mentioned as centroid colors, but I could not find these two color code from the color code of matplotlib.
Upvotes: 2
Views: 3481
Reputation: 33918
The third argument is not actually color, but format, including the color, marker style and line style. The syntax of the fmt
argument of ax.plot(x,y,fmx)
is:
fmt = '[marker][line][color]'
The documentation also gives examples:
'b' # blue markers with default shape
'or' # red circles
'-g' # green solid line
'--' # dashed line with default color
'^k:' # black triangle_up markers connected by a dotted line
The bx
means "blue x" (i.e. [color][marker]). It seems that the matplotlib plot function is clever enough to understand the fmt
even if the ordering of the items in the argument are mixed. The docs say (emphasis mine)
Other combinations such as [color][marker][line] are also supported, but note that their parsing may be ambiguous.
Hence, I would personally use xb
over bx
.
Upvotes: 3
Reputation: 320
If you look at the documentation it states that it is the style of marker. In this case a red "x" and a blue "x".
Upvotes: 0