Skip to content

Instantly share code, notes, and snippets.

@szapp
Created December 10, 2019 15:13
Show Gist options
  • Save szapp/fe6216e20298988815fadf7db7f50b0b to your computer and use it in GitHub Desktop.
Save szapp/fe6216e20298988815fadf7db7f50b0b to your computer and use it in GitHub Desktop.
Quick plotting functions
"""
Quick plotting for testing and preliminary data visualization
"""
from matplotlib import pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
import numpy as np
__all__ = [
'imshow',
]
# Default color map
dflt_cmap = LinearSegmentedColormap.from_list('rwb', ['red', 'white', 'black'])
def imshow(a, **kwargs):
mm = np.abs(a).max()
args = {
'cmap': dflt_cmap,
'vmin': -mm,
'vmax': mm,
'origin': 'lower',
}
args.update(kwargs)
plt.imshow(a, **args)
plt.colorbar()
plt.gca().xaxis.get_major_locator().set_params(integer=True)
plt.gca().yaxis.get_major_locator().set_params(integer=True)
plt.gca().set_xticks(range(int(plt.gca().get_xlim()[0]),
int(plt.gca().get_xlim()[1]) + 1), minor=True)
plt.gca().set_yticks(range(int(plt.gca().get_ylim()[0]),
int(plt.gca().get_ylim()[1]) + 1), minor=True)
@szapp
Copy link
Author

szapp commented Dec 10, 2019

Example usage:

import quickplot as qlt

qlt.imshow(np.random.rand(7, 6) * 5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment