首页 > 解决方案 > 如何删除/修改熊猫数据框图表上的轴标题?

问题描述

我正在从熊猫数据框中绘制图表,但无法删除图表上方显示“camis”的文本框,也无法更改各种轴标签。我怎么能这样做?

我试图修改所有函数参数并在这个论坛上到处查看,但没有任何内容会删除文本框或更改/添加 y 轴标签。

我正在使用以下代码:

plot2df = df.groupby("food")["camis"].count() / df_cleaned.groupby("food")["camis"].count() plot2df.plot(kind="bar",subplots = True, figsize=(4,4),ylim = (0.5,1))

附上图片也是图表

标签: pythonpandasmatplotlibgraph

解决方案


df.plot() 函数返回一个matplotlib对象。您可以在该对象上设置轴标题。

plot = plot2df.plot(kind="bar", subplots=True, figsize=(4, 4), ylim=(0.5, 1))
plot.set(xlabel="x axis title", ylabel="y axis title")
plot.show()

绘图的主标题也可以df.plot()使用 'title' 参数添加到函数中:

plot2df.plot(kind="bar", subplots=True, figsize=(4, 4),
             ylim=(0.5, 1), title="Add your title")

推荐阅读