防止matplotlib.pyplot中的科学记数法
我们在使用matplotlib.pyplot绘制图像时,如果统计的数据过大图标上就会出现用科学计数法的方式显示,例如
import matplotlib.pyplot as plt
import numpy as py
# 求平方数
x_values = py.linspace(0, 100000000)
y_value = [x**2 for x in x_values]
plt.style.use('seaborn')
fig, ax = plt.subplots()
ax.scatter(x_values, y_value, c=y_value, cmap=plt.cm.Reds, s=20)
plt.show()
可见x轴与y轴上的数据并没有显示原本的格式
解决方法如下
输入以下这行代码
ax.ticklabel_format(style='plain')
即
import matplotlib.pyplot as plt
import numpy as py
# 求平方数
x_values = py.linspace(0, 100000000)
y_value = [x**2 for x in x_values]
plt.style.use('seaborn')
fig, ax = plt.subplots()
ax.scatter(x_values, y_value, c=y_value, cmap=plt.cm.Reds, s=20)
ax.ticklabel_format(style='plain')
plt.show()
可得