Python 防止matplotlib.pyplot中出现科学符号。尝试了所有在线找到的选项,但没有一个对我有效。ticklabel\u格式是否已损坏?

Python 防止matplotlib.pyplot中出现科学符号。尝试了所有在线找到的选项,但没有一个对我有效。ticklabel\u格式是否已损坏?,python,matplotlib,Python,Matplotlib,我不熟悉python和matplotlib,现在我在pyplot中抑制科学符号有几个小时很困难。我尝试了推荐的解决方案,但没有一个奏效。我还尝试了上面列出的解决方案,但这些都不起作用。我不知所措。请帮忙 我用的是jupyter笔记本 导入的python库 import pandas as pd import numpy as np import requests import zipfile import io import xlrd %matplotlib inline import m

我不熟悉python和matplotlib,现在我在pyplot中抑制科学符号有几个小时很困难。我尝试了推荐的解决方案,但没有一个奏效。我还尝试了上面列出的解决方案,但这些都不起作用。我不知所措。请帮忙

我用的是jupyter笔记本

导入的python库

import pandas as pd
import numpy as np
import requests
import zipfile
import io
import xlrd

%matplotlib inline 

import matplotlib as mpl
import matplotlib.pyplot as plt


mpl.style.use('ggplot') # optional: for ggplot-like style

# check for latest version of Matplotlib
print ('Matplotlib version: ', mpl.__version__) # >= 2.0.0
# Matplot version: 3.1.0
当我用下面的代码创建默认的线图时,我得到y轴上的le7

# Draw Line Plot for Imigration from all countries

# years columns after the ones with no data got removed
years = list(map(str, range(1998, 2014)))

# total is a dataframe
total = df_uk.loc['Column_Total', years] # passing in years 1998 - 2013 

total.plot(kind='line')

plt.title('Immigration in UK')
plt.ylabel('Number of Immigrants')
plt.xlabel('Years')

plt.show() 
如果我试图用下面的内容来抑制科学记数法,我会得到NameError:名称“ax”未定义

ax.ticklabel_format(useOffset=False, style='plain')
total.plot(kind='line')


plt.title('Immigration in UK')
plt.ylabel('Number of Immigrants')
plt.xlabel('Years')

plt.show() 

完全错误:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-17-576bd02a7dac> in <module>
      1 # Draw Line Plot for Imigration from all countries
      2 
----> 3 ax.ticklabel_format(useOffset=False, style='plain')
      4 total.plot(kind='line')
      5 

NameError: name 'ax' is not defined
---------------------------------------------------------------------------
NameError回溯(最近一次呼叫上次)
在里面
1#绘制线图,供所有国家的移民使用
2.
---->3 ax.ticklabel_格式(useOffset=False,style='plain')
4总计。绘图(种类=线)
5.
NameError:未定义名称“ax”
请帮忙

我能够解决这个问题:)

本文帮助我理解了如何将ax与dataframe结合使用。我很困惑,因为ticklabel_格式的示例使用的是x和y的列表,而不是数据帧


# Draw Line Plot for Imigration from all countries 

fig, ax = plt.subplots()

ax.ticklabel_format(useOffset=False, style='plain')

total.plot(kind='line', ax=ax)

plt.title('Immigration in UK')
plt.ylabel('Number of Immigrants')
plt.xlabel('Years')

plt.show() 


请参阅如何定义fig和ax的副本。“
fig,ax=plt.subplot()
“@ankii你的评论把我推向了正确的方向。:)我成功地解决了它。然后发布一个答案!:)为了将来,请介绍可以在任何地方使用的变量。。比如随机列表,或满是1的数组等。@ankii我的问题完全是由于数据帧。如果我手动创建变量来说明问题,我的错误就不会出现。answer现已发布。感谢您的帮助。如果您正在使用熊猫,请使用熊猫标签。