python - 在 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 轴上没有得到预期值,我的代码有什么问题吗?
解决方案
使用情节更清洁:
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()
输出:
推荐阅读
- bash - 如何将bash命令替换输出用引号括起来
- html - 在引导程序中居中网格图像内容
- sdk - Rally 我可以在 IterationComboBox 中包含子项目的迭代吗?
- sql-server - 如何让 SQL Server 从文件中读取?
- javascript - 获取变量中的回调结果
- java - 尝试为 Minecraft 编译我的 ModCoderPack mod 时出错
- sql - SQL Server 查询允许我显示书柜中的书籍概览
- r - 如何将 xml_node 转换为 R 中的数据框(具有多个命名空间)?
- java - 输入一个单词然后在每个字母之间用斜线输出它们会导致错误
- java - JsonInclude 无法防止延迟初始化的 NULL OneToMany 关系的映射异常