import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
import matplotlib.cbook as cbook
import matplotlib.path as path
import matplotlib.patches as Pathpatch
np.random.seed(19680801)
# Fixing the seed to reproducibility
delta = 0.025
x = y = np.arange(-3., 3., delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X-1)**2 - (Y-1)**2)
Z = (Z2 - Z1)*2
fig, ax = plt.subplots()
im = ax.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn, origin='lower', extent=[-3, 3, -3, 3], vmax=abs(Z).max(), vmin=-abs(Z).max())
plt.show()
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.path as path
import matplotlib.patches as Pathpatch
import numpy as np
import matplotlib.cbook as cbook
# A simple image
with cbook.get_sample_data('/Users/menglingpeng/PycharmProjects/pythonProject/demo.jpeg') as image_file:
image = plt.imread(image_file) # get the data in the path you gave
fig, ax = plt.subplots()
plt.imshow(image)
plt.axis('off')
plt.title(r'$wife\ of\ menglingpeng$')
# A another image
# datas are 256x256 16bits Integers
w, h = 256, 256
with cbook.get_sample_data('s1045.ima.gz') as data_file:
s = data_file.read()
A = np.frombuffer(s, np.uint16).astype(float).reshape((w, h))
fig, ax = plt.subplots()
extent = [0, 25, 0, 25]
plt.imshow(A, extent=extent, cmap=plt.cm.hot, origin='lower')
plt.show()