python - "rx"或 "bx"作为 ax.plot 的第三个参数是什么意思?

标签 python matplotlib

此代码用于 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的颜色代码中找不到这两个颜色代码。

enter image description here

最佳答案

第三个参数实际上不是颜色,而是格式,包括颜色、标记样式和线条样式。 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/

相关文章:

python - 更改 Jupyter Ipython 中 matplotlib 的默认后端

python - 是否可以在 python 中加载和显示大(8296 x 14740 像素)图像?

matplotlib - 绘图排序/分层 Julia pyplot

python - 根据字符串模式从列表创建列表

python - 隐藏系统托盘中的 tkinter 窗口

python - Tkinter 消息框在按下“确定/确认”后不会消失

python - Django Mezzanine 框架 - 不允许我将视频嵌入到博客文章中

python - 为什么 matplotlib.figure.Figure 的行为与 matplotlib.pyplot.figure 如此不同

python - 如何使用 pyplot 在相同的 x 轴(日期时间)但不同的 y 轴上绘制折线图和条形图?

python - 如何用python绘制一个平行于x轴和z轴的平面?