Created
November 2, 2018 12:28
-
-
Save unutbu/28b35de1d14a64c8fbcd1101069e8ebc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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