python画图坐标轴不出现⼩数_在matplotlibp的轴上显⽰⼩数
点和科学符号
为了在科学记数法中获得格式良好的标签,可以使⽤ScalarFormatter的格式功能,它使⽤MathText(Latex)并将其应⽤于标签。import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mticker
fig, ax = plt.subplots()
晨读英语x = np.linspace(0, 300, 20)
y = np.linspace(0,300, 20)
y = y*1e16
ax.plot(x,y)
f = mticker.ScalarFormatter(uOfft=Fal, uMathText=True)
g = lambda x,pos : "${}$".format(f._formatSciNotation('%1.10e' % x))
plt.show()
虽然这在很多情况下可能有⽤,但实际上并不能满⾜问题的要求。要使所有标签上的数字相等,可以使⽤更⾃定义的版本。import matplotlib.pyplot as plt
大司寇import numpy as np
import matplotlib.ticker as mticker
fig, ax = plt.subplots()
x = np.linspace(0, 300, 20)
y = np.linspace(0,300, 20)
缺氧缺血性脑病
特拉法尔加y = y*1e16
牯岭
什么山什么水ax.plot(x,y)
手续费怎么算
class MathTextSciFormatter(mticker.Formatter):
def __init__(lf, fmt="%1.2e"):
lf.fmt = fmt
def __call__(lf, x, pos=None):
s = lf.fmt % x
decimal_point = '.'
positive_sign = '+'
tup = s.split('e')
significand = tup[0].rstrip(decimal_point)
sign = tup[1][0].replace(positive_sign, '')
exponent = tup[1][1:].lstrip('0')
if exponent:
exponent = '10^{%s%s}' % (sign, exponent)
if significand and exponent:
s = r'%s{\times}%s' % (significand, exponent)
el:
s = r'%s%s' % (significand, exponent)
return "${}$".format(s)
# Format with 2 decimal places
>矿产资源储量