python - pyplot 颜色条不显示精确值

标签 python matplotlib precision colorbar

我有一个带有颜色条的等高线图。但是,它会截断一些有效数字,并仅在侧面显示其余数字。

有没有办法更精确地显示颜色条上的有效数字(即具有更多有效数字的标签)?

最佳答案

您必须使用format argument颜色条设置您自己的颜色条标签输出格式,如下例所示:

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

# specify your own
# formatter for colorbar labels
# in return select desired format
def myfmt(x, pos):
    return '{0:.5f}'.format(x)

# test data
arr = np.random.randn(111,111) * 1.e-2
cf = plt.contourf(arr)

# apply formatter for colorbar labels
plt.colorbar(cf, format=ticker.FuncFormatter(myfmt))
plt.show()

如果你的格式化函数很简单,你必须像这里一样编写

plt.colorbar(cf, format='%.5f')

enter image description here

关于python - pyplot 颜色条不显示精确值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46226426/

相关文章:

python - 如何使用 matplotlib 为 3D 散点图创建标记大小图例?

Go:如何检查将 float64 转换为 float32 时的精度损失

python - 谷歌应用引擎中的图像 exif 数据

python - 检查数据框列是否为分类

python - 将定义线添加到堆积面积图的最简单方法是什么?

python - 如何在 Python 中的图表上显示 R 平方值

python - 如何为Django Rest Framework指定过滤数据参数?

python - 3-d numpy 数组的 2 轴上的 argmax

math - float 学坏了吗?

c++ - float 到字符串而不四舍五入