如何在pandas和matplotlib中避免出现1e7轴值

12 投票
1 回答
16014 浏览
提问于 2025-04-18 05:31

使用下面的代码会生成一个图表,y轴的范围是从0.0到2.5乘以10的7次方。请问有什么方法可以避免出现1乘以10的7次方的值呢?

    import pandas as pd
    import matplotlib.pyplot as plt
    a = {'Test1': {1: 21867186, 4: 20145576, 10: 18018537},
         'Test2': {1: 23256313, 4: 21668216, 10: 19795367}}

    d = pd.DataFrame(a).T
    #print d

    f = plt.figure()

    plt.title('Title here!', color='black')
    d.plot(kind='bar', ax=f.gca())
    plt.show()

1 个回答

14

使用 ticklabel_format(style = 'plain'),就像下面这个例子一样。

import pandas as pd
import matplotlib.pyplot as plt
a = {'Test1': {1: 21867186, 4: 20145576, 10: 18018537},
     'Test2': {1: 23256313, 4: 21668216, 10: 19795367}}

d = pd.DataFrame(a).T
#print d

f = plt.figure()

plt.ticklabel_format(style = 'plain')

plt.title('Title here!', color='black')
d.plot(kind='bar', ax=f.gca())
plt.show()

我希望这正是你想要的。

撰写回答