此代码用于 KMeans 机器学习:
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)
这里的bx,rx是什么意思,我可以看到提到的是质心颜色,但是我在matplotlib的颜色代码中找不到这两个颜色代码。
最佳答案
第三个参数实际上不是颜色,而是格式,包括颜色、标记样式和线条样式。 ax.plot(x,y,fmx)
的 fmt
参数的语法为:
fmt = '[marker][line][color]'
documentation还给出了例子:
'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
bx
表示“蓝色 x”(即[颜色][标记])。看来 matplotlib 绘图函数足够聪明,可以理解 fmt,即使参数中项目的顺序是混合的。文档说(强调我的)
Other combinations such as [color][marker][line] are also supported, but note that their parsing may be ambiguous.
因此,我个人会使用 xb
而不是 bx
。
关于python - "rx"或 "bx"作为 ax.plot 的第三个参数是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64784642/