相关疑难解决方法(0)

Python matplotlib colorbar科学记谱法基础

我正在尝试在matpllotlib contourf图上自定义颜色条.虽然我能够使用科学记数法,但我试图改变符号的基础 - 主要是因为我的刻度将在(-100,100)而不是(-10,10)的范围内.

例如,这会产生一个简单的情节......

import numpy as np
import matplotlib.pyplot as plt

z = (np.random.random((10,10)) - 0.5) * 0.2

fig, ax = plt.subplots()
plot = ax.contourf(z)
cbar = fig.colorbar(plot)

cbar.formatter.set_powerlimits((0, 0))
cbar.update_ticks()

plt.show()
Run Code Online (Sandbox Code Playgroud)

像这样:

在此输入图像描述

但是,我希望颜色条上方的标签为1e-2,数字范围为-10到10.

我该怎么做?

python matplotlib colorbar contourf

10
推荐指数
1
解决办法
3630
查看次数

在matplotlib轴上设置科学限制后调整指数文本

目前,如果我将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)

python matplotlib

7
推荐指数
2
解决办法
6081
查看次数

标签 统计

matplotlib ×2

python ×2

colorbar ×1

contourf ×1