【发布时间】:2023-01-18 01:08:12
【问题描述】:
我正在尝试从 csv 文件中绘制一些数据。我使用 Pandas 加载 csv 文件。我正在使用 sns.lineplot() 绘制线条。但其中的一个传说总是错误的。它在图例之一周围显示了一个正方形。
plt.figure(dpi=150)
lin1 = sns.lineplot(x = "Training time", y = "Relative L2 error", data=df[df["Activation"]=="tanh"])
lin2 = sns.lineplot(x = "Training time", y = "Relative L2 error", data=df[df["Activation"]=="silu"])
lin3 = sns.lineplot(x = "Training time", y = "Relative L2 error", data=df[df["Activation"]=="swish"])
plt.xlabel("Training time (sec)")
plt.legend(("tanh", "silu", "swish"))
plt.yscale('log',base=10)
我用了3个不同的函数,因为Activations比较多。这是结果图。
情节看起来是正确的,但传说正在制造问题。以下是我正在使用的绘图工具的版本。
Python 3.9.12
matplotlib 3.6.1
matplotlib-inline 0.1.6
seaborn 0.12.1
我在互联网上找不到同样的问题。内核重启无济于事。如果需要更多信息,请告诉我。
【问题讨论】:
-
你能用
plt.plot(...)代替seaborn吗?通过使用plt.plot(...),您可以使用参数label设置图例。
标签: python matplotlib seaborn legend