python bar plot_Python matplotlib colorbar科学记谱法基础

一个可能的解决方案可以是ScalarFormatter的子类并修复此问题中的数量级:Set scientific notation with fixed exponent and significant digits for multiple subplots

然后,您将调用此格式化程序,其数量级为参数顺序,OOMFormatter(-2,mathText = False). mathText设置为false以从问题中获取符号,即

将其设置为True时,将给出.

然后,您可以通过colorbar的format参数将格式化程序设置为colorbar.

import numpy as np; np.random.seed(0)

import matplotlib.pyplot as plt

import matplotlib.ticker

class OOMFormatter(matplotlib.ticker.ScalarFormatter):

def __init__(self, order=0, fformat="%1.1f", offset=True, mathText=True):

self.oom = order

self.fformat = fformat

matplotlib.ticker.ScalarFormatter.__init__(self,useOffset=offset,useMathText=mathText)

def _set_orderOfMagnitude(self, nothing):

self.orderOfMagnitude = self.oom

def _set_format(self, vmin, vmax):

self.format = self.fformat

if self._useMathText:

self.format = '$%s$' % matplotlib.ticker._mathdefault(self.format)

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

fig, ax = plt.subplots()

plot = ax.contourf(z)

cbar = fig.colorbar(plot, format=OOMFormatter(-2, mathText=False))

plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值