代码之家  ›  专栏  ›  技术社区  ›  DataGuy

Matplotlib X轴,关闭一个名称

  •  1
  • DataGuy  · 技术社区  · 7 年前

    我使用两个列表来填充matplotlib中的简单线图:

    X轴=结果[]和 Y轴=名称[]

    以下是“名称”包含的内容: ['rf'、'gbr'、'knn'、'cart'、'svm'、'nn'、'ada']

    下面是“结果”包含的内容:

    [0.8941514126644701, 0.8821308167746561, 0.7864150401953114, 0.8120543244109, 0.1426674582201032, 0.7439163675782782, 0.7350927779887548]。

    我使用一个简单的绘图布局,如下所示:

    fig=plt.figure(FigSize=(9,6))。
    图SUPTITLE(“算法比较”)
    ax=图添加子批次(111)
    plt.图(结果)
    ax.设置标签(名称)
    请显示())
    

    但我的情节被列表中的一个元素缩短了;这里是它看起来的样子:

    我这里缺什么?

    “结果”包含以下内容:

    [0.8941514126644701, 0.8821308167746561, 0.7864150401953114, 0.8120543244109, 0.1426674582201032, 0.7439163675782782, 0.7350927779887548条]

    我对绘图使用简单的布局,如下所示:

    fig = plt.figure(figsize=(9,6))
    fig.suptitle('Algorithm Comparison')
    ax = fig.add_subplot(111)
    plt.plot(results)
    ax.set_xticklabels(names)
    plt.show()
    

    但我的情节被列表中的一个元素缩短了;下面是它的样子:

    enter image description here

    我这里缺什么?

    2 回复  |  直到 7 年前
        1
  •  1
  •   ImportanceOfBeingErnest    7 年前

    fig = plt.figure(figsize=(9,6))
    fig.suptitle('Algorithm Comparison')
    ax = fig.add_subplot(111)
    plt.plot(results)
    ax.set_xticks(list(range(len(results))))
    ax.set_xticklabels(names)
    plt.show()
    

    fig = plt.figure(figsize=(9,6))
    fig.suptitle('Algorithm Comparison')
    ax = fig.add_subplot(111)
    plt.plot(names, results)
    plt.show()
    
        2
  •  0
  •   mostlyoxygen    7 年前

    ax.get_xticks()

    [-1.  0.  1.  2.  3.  4.  5.  6.  7.]
    

    plot

    ax.set_xticks(range(len(names)))