Pandas线打印跳过x标签

2024-09-30 20:34:32 发布

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

我有一个数据框架,以流派作为索引,列中有%的男性和%的女性

enter image description here

我绘制绘图的代码如下所示:

dfPercentile.plot(figsize = (20,10))

但x轴并没有显示所有类型的价值。它只展示了很少的动作片、犯罪片和惊悚片,如下图所示

enter image description here

在xaxis上显示所有类型的标签,我遗漏了什么


Tags: 数据代码框架绘图类型plot绘制价值
1条回答
网友
1楼 · 发布于 2024-09-30 20:34:32

您可以这样打印它们:

import string
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.randint(0,100,(26,2)), index=[*string.ascii_lowercase])

ax=df.plot()
ax.set_xticks(list(np.arange(df.shape[0])))
ax.set_xticklabels(df.index)

输出:

enter image description here

相关问题 更多 >