[英]Set 'y' axis to scientific notation
I want my y axis to be formatted in scientific notation.我希望我的 y 轴以科学记数法进行格式化。
I have tried the matplotlib documentation , but it ignores my command.我已经尝试过matplotlib 文档,但它忽略了我的命令。
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randint(1e4, size=200)
y = np.random.randint(1e4, size=200)
plt.ticklabel_format(axis='both', style='sci')
plt.xlabel('x')
plt.ylabel('y')
plt.scatter(x,y, color='b', s=5, marker=".")
plt.show()
My output just appears in none-scientific notation.我的输出只是以非科学符号出现。
For example I expect the ylabel 1000
to be 1E03
.例如,我希望 ylabel 1000
为1E03
。
This code is just an example.这段代码只是一个例子。
I have a sub-plot where plot 1 and 3 are in scientific notation, but plot 2 is in non-scientific notation.我有一个子图,其中图 1 和图 3 使用科学记数法,但图 2 使用非科学记数法。
Thanks.谢谢。
You should just add scilimits=(4,4)
to your command您应该将scilimits=(4,4)
添加到您的命令中
plt.ticklabel_format(axis='both', style='sci', scilimits=(4,4))
for example your code will become:例如你的代码将变成:
x = np.random.randint(1e4,size=200)
y = np.random.randint(1e4,size=200)
plt.ticklabel_format(axis='both', style='sci', scilimits=(4,4))
plt.xlabel('x')
plt.ylabel('y')
plt.scatter(x,y, color='b', s=5, marker=".")
plt.show()
Passing通过
plt.ticklabel_format(axis='both', style='sci', scilimits=(0,0))
worked for me.为我工作。
(as @Meysam-Sadeghi suggested, but without plt.subplots()) (正如@Meysam-Sadeghi 所建议的,但没有 plt.subplots())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.