简体   繁体   English

将“y”轴设置为科学记数法

[英]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 10001E03

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.

相关问题 PyQtgraph y 轴标签非科学记数法 - PyQtgraph y axis label non scientific notation 在matplotlib中将科学计数法指数移动到y轴的右侧 - Move scientific notation exponential to right side of y axis in matplotlib Seaborn / Matplotlib:如何在事实y轴上抑制科学记数法 - Seaborn / Matplotlib: How to repress scientific notation in factorplot y-axis 绘制多个条形图时,科学计数法 Y 轴 label - Y axis label in scientific notation when multiple bar charts are plotted Matplotlib:将 Y 轴更改为对数刻度后,将 Y 轴设置为无科学计数法 - Matplotlib: setting the Y-axis to none scientific notation AFTER changing the Y-axis to log scale 在对数图上设置自定义科学记数法 y - Set custom scientific notation y tick on log-plot matplotlib 中轴上的尴尬科学计数法 - Awkward scientific notation on the axis in matplotlib 在 Altair 中将轴缩放为科学记数法 - Scale an axis to scientific notation in Altair 如何在 matplotlib 中使 y 轴上的数字显示以百万为单位的值而不是科学计数法? - How do I make the numbers on the y-axis show values in millions instead of in scientific notation in matplotlib? 将 y 轴 label 格式化为具有多个零的科学计数法的更高千位? - Format the y-axis label in the higher thousands with many zeros to scientific notation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM