目前,如果我将matplotlib y轴刻度标签设置为科学模式,它会在表格的y轴顶部给出一个指数 1e-5
我想将其调整为读取,r'$\mathregular{10^{-5}}$'以便打印出来.
这是我的示例代码:
# Create a figure and axis
fig, ax = plt.subplots()
# Plot 100 random points
# the y values of which are very small
ax.scatter(np.random.rand(100), np.random.rand(100)/100000.0)
# Set the y limits appropriately
ax.set_ylim(0, 1/100000.0)
# Change the y ticklabel format to scientific format
ax.ticklabel_format(axis='y', style='sci', scilimits=(-2, 2))
# Get the offset value
offset = ax.yaxis.get_offset_text()
# Print it out
print '1st offset printout: {}'.format(offset)
# Run plt.tight_layout()
plt.tight_layout()
# Print out offset again …Run Code Online (Sandbox Code Playgroud)