Skip to content

Instantly share code, notes, and snippets.

@unutbu
Created November 2, 2018 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unutbu/28b35de1d14a64c8fbcd1101069e8ebc to your computer and use it in GitHub Desktop.
Save unutbu/28b35de1d14a64c8fbcd1101069e8ebc to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mticker
img = np.random.randn(300,300)*10**-6
myplot = plt.imshow(img)
class FixedOrderFormatter(mticker.ScalarFormatter):
# http://stackoverflow.com/questions/3677368/#3679918 (Joe Kington)
"""Formats axis ticks using scientific notation with a constant order of
magnitude"""
def __init__(self, order_of_mag=0, useOffset=True, useMathText=False):
self._order_of_mag = order_of_mag
mticker.ScalarFormatter.__init__(self, useOffset=useOffset,
useMathText=useMathText)
def _set_orderOfMagnitude(self, range):
"""Over-riding this to avoid having orderOfMagnitude reset elsewhere"""
self.orderOfMagnitude = self._order_of_mag
plt.colorbar(myplot, format=FixedOrderFormatter(1))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment