Pandas数据可视化表中的标签

2024-10-04 01:31:39 发布

您现在位置:Python中文网/ 问答频道 /正文

你知道吗 嗨,我正在绘制熊猫数据帧。熊猫数据框如下所示:

;Cosine;Neutralized
author;0.842075;0.641600
genre;0.839696;0.903227
author+genre;0.833966;0.681121

我使用的绘图代码是:

fig = ari_total.plot(kind="bar", legend = False, colormap= "summer",
                     figsize= ([7,6]), title = "Homogeinity "+corpora+" (texts: "+str(amount_texts)+")", table=True,
                    use_index=False, ylim =[0,1]).get_figure()

结果很好,但有一个问题: enter image description here

如您所见,表“author”、“genre”和“author+gender”的索引中的lab呈现为0、1和2以上。你知道吗

我的问题是:如何删除这些数字,并且仍然使用相同的函数?我正在使用参数use\u index=False,我以为他们会从条中删除标签,但实际上它只会用这个数字替换它们。。。你知道吗

如果你能帮忙,我将非常感激。当做!你知道吗


Tags: 数据代码false绘图indexusefig绘制
1条回答
网友
1楼 · 发布于 2024-10-04 01:31:39

使用fig.axes[0].get_xaxis().set_visible(False)。你知道吗

代码:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame()
df['Cosine'] = [0.842075,0.839696,0.833966]
df['Neutralized'] = [0.641600,0.903227,0.681121]
df.index = ['author', 'genre', 'author+genre']
fig = df.plot(kind="bar", legend = False, colormap= "summer",
                     figsize= ([7,6]), title = "whatever", table=True,
                    use_index=False, ylim =[0,1]).get_figure()
fig.axes[0].get_xaxis().set_visible(False)
plt.show()

结果:

enter image description here

相关问题 更多 >