线图聚焦于大Pandas矢状核的特定范围

2024-09-30 03:23:34 发布

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

我有一张像这样的桌子

Age     Income
16      90000
18    2000000
19      60000
20      60000
21      50000
22      60000
23      55000
24      50000
26      63333
27      50000
28    1030000
29      20000
31      45000
33      70000
34      50000
35      43333
36      20000
37      20000
38      80000
39      50000
40      80000
41      60000
42      40000
43      35000
44      60000
45      55000
46      65000
47      50000
48    2000000
49    2000000

这个表格是

tableA.groupby(['Age'])['Rounded_Incomes'].mean().astype(int).plot(kind='line')

因为有些收入非常大,比如2000000或1030000。。结果是:

enter image description here

如何绘制线字符集中在18000~80000这样的小数字上,但图中仍然有大数字(1030000/2000000)

谢谢


Tags: ageplotline数字mean表格intgroupby
1条回答
网友
1楼 · 发布于 2024-09-30 03:23:34
import matplotlib.pyplot as plt

tableA.groupby(['Age'])['Rounded_Incomes'].mean().astype(int).plot(kind='line')
plt.ylim(18000, 80000)

另外,把你的y轴放在一个对数刻度上可能会有所帮助

tableA.groupby(['Age'])['Rounded_Incomes'].mean().astype(int).plot(kind='line', logy=True)

相关问题 更多 >

    热门问题