【问题标题】:how to set x, y label individually for scatter plots created using for loop?如何为使用 for 循环创建的散点图单独设置 x、y 标签?
【发布时间】:2021-11-27 14:50:58
【问题描述】:

我有 1 个 y 变量和数百个 X 变量,我想通过 for 循环创建散点图。我有允许我生成绘图的代码,但我也需要相应地标记 x、y 标签。我怎样才能做到这一点?任何帮助表示赞赏。

代码如下:

figures = []

for column in X_uni:
    f = plt.figure(figsize=(6,6))
    figures += [f]  # This appends a figure f to the list of figures
    ax = plt.axes()
    ax.plot(X_uni[column], y_data, marker = 'o', ls='', ms = 3.0)

【问题讨论】:

    标签: python for-loop matplotlib scatter-plot


    【解决方案1】:

    使用

    ax.set_xlabel(column)
    

    在你的 for 循环中。并添加一个ylabel:

    ax.set_ylabel("ylabel")
    

    【讨论】:

    • 非常感谢您的帮助。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多