如何从轴matplotlib中删除指数

8zzbczxx  于 2023-01-31  发布在  其他
关注(0)|答案(1)|浏览(121)

我想知道是否有办法删除每个轴上的1 e12和1 e-6。我想只保留整数。

h = 6.62607015E-34
c = 299792458
k = 1.380649E-23
T = 3600

Lambda = np.linspace(0.01, 5,500)*10**-6

def flux(h,c,Lambda,T,k):
    return ((2*3.14*h*c**2) / (Lambda**5)) * 1/(math.e**( (h*c)/ (Lambda*k*T) ) -1)

plt.plot(Lambda, flux(h,c,Lambda,T,k))
b4lqfgs4

b4lqfgs41#

可以使用matplotlib中的xticks和yticks方法更改x轴和y轴上的刻度标签,也可以设置刻度位置和相应的标签,或者设置刻度位置并让matplotlib自动格式化标签,下面是后者的示例:

import numpy as np
import math
import matplotlib.pyplot as plt

h = 6.62607015E-34
c = 299792458
k = 1.380649E-23
T = 3600

Lambda = np.linspace(0.01, 5, 500) * 10**-6

def flux(h, c, Lambda, T, k):
    return ((2*math.pi*h*c**2) / (Lambda**5)) * 1/(math.e**( (h*c)/ (Lambda*k*T) ) -1)

plt.plot(Lambda, flux(h, c, Lambda, T, k))
plt.xlabel('Wavelength (µm)')
plt.ylabel('Flux (W/m^2)')

plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
plt.gca().yaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))

plt.show()

这将格式化x轴和y轴刻度标签以仅显示整数。

相关问题