首页 > 解决方案 > 在 matplotlib python 中没有得到预期的结果

问题描述

在 y 轴上没有得到预期值,我的代码有什么问题吗? 情节正在得到情节预期

import matplotlib.pyplot as plt
x_values = list(range(1,1001))

y_values = [ x**2 for x in x_values]
plt.scatter(x_values,y_values,s=40)

plt.title("scattered squares 2",fontsize=15)
plt.xlabel("value",fontsize=14)
plt.ylabel("square of value",fontsize=15)
# Set the range for each axis.
plt.axis([0,1100,0,1100000])
plt.show()

在 y 轴上没有得到预期值,我的代码有什么问题吗?

标签: pythonmatplotlib

解决方案


使用情节更清洁:

import matplotlib.pyplot as plt
x_values = list(range(1,1001))

y_values = [ x**2 for x in x_values]

plt.ticklabel_format(style='plain') #< ---- here
plt.title("scattered squares 2",fontsize=15)
plt.xlabel("value",fontsize=14)
plt.ylabel("square of value",fontsize=15)
# Set the range for each axis.
plt.plot(x_values,y_values)
plt.show()

输出:

在此处输入图像描述


推荐阅读